chilts / mongodb-queue

Message queues which uses MongoDB.
209 stars 92 forks source link

Fix intermittent test failures that are based on timing queries. #17

Closed david-martin closed 7 years ago

david-martin commented 7 years ago

Hi @chilts, I had a look into the intermittent test failures and believe this should help. This problem only happens if the visible timestamp is exactly the same as the timestamp when trying to get a job.

This fix changes the queue.get() functionality slightly by using 'less than or equal to' ($lte) when comparing to the current time. This ensures that any newly added jobs to a queue can be retrieved straight away i.e. a test can add a job, then get it without having to wait until a small amount of time has passed and the job is 'visible'.

chilts commented 7 years ago

Wow, cool, thanks @david-martin. It sounds like your root cause analysis is correct. Quick question though. Do you think this will affect anything else in the system? I had a quick look through and I think it'll be fine.

I think Queue.prototype.size would also need changing to be $lte though this is more about consistency than trying to get the exact numbers. Would you be able to add this too?

I must admit, this also makes ping, ack and inFlight compliment add and size better since $gt is the perfect compliment to $lte already.

david-martin commented 7 years ago

@chilts I've updated the PR with the suggested change. From my understanding, it shouldn't affect anything else in the system.

That makes sense about the change complimenting the $gt in other functions.

chilts commented 7 years ago

Released as v3.0.0 - not a major change, but I guess it is different (therefore, breaking). https://www.npmjs.com/package/mongodb-queue

Many thanks again @david-martin. :)