diff options
author | Svilen Mihaylov <svilen.mihaylov@mongodb.com> | 2020-05-27 10:53:31 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-01 14:46:38 +0000 |
commit | e9e59e53f4788d0ab26ffdacd3c0d03b75b6204b (patch) | |
tree | a1e944e1f019550b53e6f7d4eca55e00082cc6c0 /jstests/sharding | |
parent | a3c3db2aa15a12443f531750c28a1e408bda32dd (diff) | |
download | mongo-e9e59e53f4788d0ab26ffdacd3c0d03b75b6204b.tar.gz |
SERVER-48442: Fix change_streams.js to test events in any order
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/change_streams.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/jstests/sharding/change_streams.js b/jstests/sharding/change_streams.js index 08c075c1e18..e020aa3a866 100644 --- a/jstests/sharding/change_streams.js +++ b/jstests/sharding/change_streams.js @@ -128,23 +128,34 @@ function runTest(collName, shardKey) { assert.writeOK(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( |