Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes share/sharedb-mongo#131
This change attempts to fix some tests that are flaky in
sharedb-mongo
.The flakiness can be reproduced locally by wrapping the
Agent._querySubscribe()
call to_fetchBulkOps()
in a longsetTimeout()
:This forces us into an edge case where the subscribe query triggers and returns the diff from a
queryPoll()
, which triggers the tests''insert'
handlers, finishes the test, and closes the backend, all before the_fetchBulkOps()
call is issued (which subsequently fails because the database has been closed).Handling this query subscribe actually triggers a variety of responses to be sent to the client at different times:
_querySubscribe()
callback (which ultimately triggersagent._reply()
in response to the original request)_fetchBulkOps()
queryPoll()
In order to reduce flakiness, this change adds checks that the query's
'ready'
event has been called, which will happen once the resubscribe request has been replied to by theAgent
.This ensures we've waited for events 1 & 3 of the above list, although we notably aren't waiting for event 2 (which is where the error is actually coming from).
Since no ops will actually be sent to the client, I'm not sure how best to wait for this. Hopefully waiting for the subscribe ack should be sufficient.