Skip to content

Commit 7d1f547

Browse files
committed
test: fix a number of our most notorious flakey tests
- 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`
1 parent a1b0802 commit 7d1f547

File tree

9 files changed

+601
-683
lines changed

9 files changed

+601
-683
lines changed

lib/core/wireprotocol/get_more.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ function getMore(server, ns, cursorState, batchSize, options, callback) {
6262
return;
6363
}
6464

65+
const cursorId =
66+
cursorState.cursorId instanceof Long
67+
? cursorState.cursorId
68+
: Long.fromNumber(cursorState.cursorId);
69+
6570
const getMoreCmd = {
66-
getMore: cursorState.cursorId,
71+
getMore: cursorId,
6772
collection: collectionNamespace(ns),
6873
batchSize: Math.abs(batchSize)
6974
};

test/examples/change_streams.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ describe('examples(change-stream):', function() {
127127
});
128128
looper.run();
129129

130+
let processChange;
131+
const streamExampleFinished = new Promise(resolve => {
132+
processChange = resolve;
133+
});
134+
130135
// Start Changestream Example 3
131136
const collection = db.collection('inventory');
132137
const changeStream = collection.watch();
@@ -138,7 +143,7 @@ describe('examples(change-stream):', function() {
138143

139144
newChangeStream = collection.watch({ resumeAfter: resumeToken });
140145
newChangeStream.on('change', next => {
141-
// process next document
146+
processChange(next);
142147
});
143148
});
144149
// End Changestream Example 3
@@ -155,6 +160,8 @@ describe('examples(change-stream):', function() {
155160
// End Changestream Example 3 Alternative
156161

157162
await newChangeStreamIterator.close();
163+
164+
await streamExampleFinished;
158165
await newChangeStream.close();
159166
await looper.stop();
160167

0 commit comments

Comments
 (0)