Skip to content

Commit 7baa85e

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 62d80e4 commit 7baa85e

File tree

9 files changed

+604
-684
lines changed

9 files changed

+604
-684
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
@@ -124,6 +124,11 @@ describe('examples(change-stream):', function() {
124124
});
125125
looper.run();
126126

127+
let processChange;
128+
const streamExampleFinished = new Promise(resolve => {
129+
processChange = resolve;
130+
});
131+
127132
// Start Changestream Example 3
128133
const collection = db.collection('inventory');
129134
const changeStream = collection.watch();
@@ -135,7 +140,7 @@ describe('examples(change-stream):', function() {
135140

136141
newChangeStream = collection.watch({ resumeAfter: resumeToken });
137142
newChangeStream.on('change', next => {
138-
// process next document
143+
processChange(next);
139144
});
140145
});
141146
// End Changestream Example 3
@@ -152,6 +157,8 @@ describe('examples(change-stream):', function() {
152157
// End Changestream Example 3 Alternative
153158

154159
await newChangeStreamIterator.close();
160+
161+
await streamExampleFinished;
155162
await newChangeStream.close();
156163
await looper.stop();
157164

0 commit comments

Comments
 (0)