Skip to content

Commit

Permalink
test: fix a number of our most notorious flakey tests
Browse files Browse the repository at this point in the history
 - remove most `core/operations.test.js` tests using cursors in a
   sharded environment. We already have coverage for these commands
   and the returned batch sizes from our internal `_next` method
   are inconsistent

 - massive overhaul of the change streams tests which ensure that
   all async operations are awaited before cleanup, and that the
   change stream and client are closed in the correct order

 - refactor of the `defer` plugin to ensure that deferred actions
   happen LIFO, and in order rather than all at the same time

 - ensure `Long` is always sent for `getMore` commands, leading to
   flakey CSFLE tests

 - introduced `EventCollector` and renamd existing class to
   `APMEventCollector`
  • Loading branch information
mbroadst committed Jun 10, 2020
1 parent 4aae1bd commit 7cab088
Show file tree
Hide file tree
Showing 9 changed files with 592 additions and 670 deletions.
7 changes: 6 additions & 1 deletion lib/cmap/wire_protocol/get_more.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ function getMore(server, ns, cursorState, batchSize, options, callback) {
return;
}

const cursorId =
cursorState.cursorId instanceof Long
? cursorState.cursorId
: Long.fromNumber(cursorState.cursorId);

const getMoreCmd = {
getMore: cursorState.cursorId,
getMore: cursorId,
collection: collectionNamespace(ns),
batchSize: Math.abs(batchSize)
};
Expand Down
9 changes: 8 additions & 1 deletion test/examples/change_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ describe('examples(change-stream):', function() {
});
looper.run();

let processChange;
const streamExampleFinished = new Promise(resolve => {
processChange = resolve;
});

// Start Changestream Example 3
const collection = db.collection('inventory');
const changeStream = collection.watch();
Expand All @@ -138,7 +143,7 @@ describe('examples(change-stream):', function() {

newChangeStream = collection.watch({ resumeAfter: resumeToken });
newChangeStream.on('change', next => {
// process next document
processChange(next);
});
});
// End Changestream Example 3
Expand All @@ -155,6 +160,8 @@ describe('examples(change-stream):', function() {
// End Changestream Example 3 Alternative

await newChangeStreamIterator.close();

await streamExampleFinished;
await newChangeStream.close();
await looper.stop();

Expand Down
Loading

0 comments on commit 7cab088

Please sign in to comment.