diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2017-12-04 13:23:00 -0500 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2017-12-07 10:25:13 -0500 |
commit | 1fd23dfafd2127c00cf47ae4d5acef75d6546def (patch) | |
tree | 340953bc2ba53470e3cec9639b73ac117bbb8551 | |
parent | a36bc9925fdb5e9b3e146870b081074708e7aba5 (diff) | |
download | mongo-1fd23dfafd2127c00cf47ae4d5acef75d6546def.tar.gz |
SERVER-32131 ChangeStreams lookup_post_image.js test makes assumptions that don't hold up in secondary read passthrough
-rw-r--r-- | jstests/change_streams/lookup_post_image.js | 10 | ||||
-rw-r--r-- | jstests/libs/fixture_helpers.js | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/jstests/change_streams/lookup_post_image.js b/jstests/change_streams/lookup_post_image.js index bba5021e393..bbf2b8027c7 100644 --- a/jstests/change_streams/lookup_post_image.js +++ b/jstests/change_streams/lookup_post_image.js @@ -7,6 +7,7 @@ load("jstests/libs/change_stream_util.js"); load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection. + load("jstests/libs/fixture_helpers.js"); // For awaitLastOpCommitted(). load("jstests/replsets/libs/two_phase_drops.js"); // For 'TwoPhaseDropCollectionTest'. let cst = new ChangeStreamTest(db); @@ -106,6 +107,11 @@ }); assert.writeOK(coll.update({_id: "fullDocument is lookup"}, {$set: {updatedAgain: true}})); assert.writeOK(coll.remove({_id: "fullDocument is lookup"})); + // If this test is running with secondary read preference, it's necessary for the remove + // to propagate to all secondary nodes and be available for majority reads before we can + // assume looking up the document will fail. + FixtureHelpers.awaitLastOpCommitted(); + latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "update"); assert(latestChange.hasOwnProperty("fullDocument")); @@ -153,6 +159,10 @@ assert.soon(function() { return !TwoPhaseDropCollectionTest.collectionIsPendingDropInDatabase(db, coll.getName()); }); + // If this test is running with secondary read preference, it's necessary for the drop + // to propagate to all secondary nodes and be available for majority reads before we can + // assume looking up the document will fail. + FixtureHelpers.awaitLastOpCommitted(); // Check the next $changeStream entry; this is the test document inserted above. latestChange = cst.getOneChange(cursor); diff --git a/jstests/libs/fixture_helpers.js b/jstests/libs/fixture_helpers.js index 52f6f976709..90d9b25d599 100644 --- a/jstests/libs/fixture_helpers.js +++ b/jstests/libs/fixture_helpers.js @@ -42,6 +42,17 @@ var FixtureHelpers = (function() { } /** + * Uses ReplSetTest.awaitLastOpCommitted() on each replica set in the fixture (besides the + * config servers) to wait for the last oplog entry on the respective primary to be visible in + * the committed snapshot view of the oplog on all secondaries. + * + * Asserts if the fixture is a standalone or if the shards are standalones. + */ + function awaitLastOpCommitted() { + _getAllReplicas().forEach((replSet) => replSet.awaitLastOpCommitted()); + } + + /** * Runs the command given by 'cmdObj' on the database given by 'dbName' on each replica set in * the fixture (besides the config servers). Asserts that each command works, and returns an * array with the responses from each shard, or with a single element if the fixture was a @@ -74,6 +85,7 @@ var FixtureHelpers = (function() { return { awaitReplication: awaitReplication, + awaitLastOpCommitted: awaitLastOpCommitted, runCommandOnEachPrimary: runCommandOnEachPrimary, getPrimaryForNodeHostingDatabase: getPrimaryForNodeHostingDatabase, }; |