summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvilen Mihaylov <svilen.mihaylov@mongodb.com>2020-05-27 10:53:31 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-02 18:14:54 +0000
commit1c05f9d9e4a7deb7fd3ca4d7874be6d18c4f7192 (patch)
treea3e2bd3fbb744d8d3a8de295f646b764ccdcbc30
parent8887c274e9e05ef9bde4b44ac9174f38c4421ba5 (diff)
downloadmongo-1c05f9d9e4a7deb7fd3ca4d7874be6d18c4f7192.tar.gz
SERVER-48442: Fix change_streams.js to test events in any order
-rw-r--r--jstests/sharding/change_streams.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/jstests/sharding/change_streams.js b/jstests/sharding/change_streams.js
index c9a9c41fa1c..22ecb4bf295 100644
--- a/jstests/sharding/change_streams.js
+++ b/jstests/sharding/change_streams.js
@@ -136,23 +136,34 @@ function runTest(collName, shardKey) {
assert.commandWorked(mongosColl.update({a: 0}, {$set: {b: 2}}, {multi: true}));
- assert.soon(() => changeStream.hasNext());
- assertChangeStreamEventEq(changeStream.next(), {
+ const expectedEvent1 = {
operationType: "update",
ns: {db: mongosDB.getName(), coll: mongosColl.getName()},
documentKey: makeShardKeyDocument(-10),
updateDescription: {updatedFields: {b: 2}, removedFields: []},
- });
+ };
- assert.soon(() => changeStream.hasNext());
- assertChangeStreamEventEq(changeStream.next(), {
+ const expectedEvent2 = {
operationType: "update",
ns: {db: mongosDB.getName(), coll: mongosColl.getName()},
documentKey: makeShardKeyDocument(10),
updateDescription: {updatedFields: {b: 2}, removedFields: []},
- });
+ };
+
+ // The multi-update events can be observed in any order, depending on the clusterTime at which
+ // they are written on each shard.
+ const expectedEvents = [expectedEvent1, expectedEvent2];
+
+ const actualEvents = [];
+ for (let expectedEvent of expectedEvents) {
+ assert.soon(() => changeStream.hasNext());
+ const actualEvent = changeStream.next();
+ actualEvents.push(pruneOptionalFields(actualEvent, expectedEvent));
+ }
changeStream.close();
+ assert.sameMembers(actualEvents, expectedEvents);
+
// Test that it is legal to open a change stream, even if the
// 'internalQueryProhibitMergingOnMongos' parameter is set.
assert.commandWorked(