summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2017-12-04 13:23:00 -0500
committerMatthew Russotto <matthew.russotto@10gen.com>2017-12-12 12:26:47 -0500
commit832e02e640ac744895168cc9209d8b5cfbfdfbc5 (patch)
tree15fb5022b54ba30555e34ebeb0d913f6942ad0e1
parentfbc1248604839045e00d692c17db9942766fd864 (diff)
downloadmongo-832e02e640ac744895168cc9209d8b5cfbfdfbc5.tar.gz
SERVER-32131 ChangeStreams lookup_post_image.js test makes assumptions that don't hold up in secondary read passthrough
(cherry picked from commit 1fd23dfafd2127c00cf47ae4d5acef75d6546def)
-rw-r--r--jstests/change_streams/lookup_post_image.js10
-rw-r--r--jstests/libs/fixture_helpers.js12
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,
};