I am using a mongo in memory test fixture loader that gets primed before each test. Normally works flawlessly.
I have a function getSample
that makes a db call that I test using AVA. Wanting to call this multiple time with different parameters (timestamps) I tried this:
const timestamps = [ '2017-08-14T00:00:00.000Z', '2017-08-13T00:00:00.000Z']
const tasks = timestamps.map(t => getSample(t))
const samples = await Promise.all(tasks)
This failed in an interesting way. My first call works (db results are there) and all others return an empty set - no errors).
Changing code to this format works. All loop instances find the collection and content.
let samples = []
for (let t of timestamps) {
samples.push(await getSample(t))
}
const getSample = async () => {
const c = await getCollection('foo') // fetches open mongo connection and returns collection
return c.find().toArray()
}
With a standard Mongo DB things work fine. But evidently there is a difference in how these 2 pieces of code work and I'd like to understand what that is. To be clear I am not looking for a fix for my in memory db - more wanting to understand what might be happening.
It might be related to this SO post but not certain.