summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2020-05-21 16:44:10 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-05 19:29:59 +0000
commit467ab964f401a6922758cacfc84a345be340441e (patch)
tree632812591be28cc1bccf99947b698398e310f4ef /jstests
parent4e3f3b96826772baa777b7563b38574c1e11c2e4 (diff)
downloadmongo-467ab964f401a6922758cacfc84a345be340441e.tar.gz
SERVER-48379 Make ReplSetTest wait for secondaries before checking db hashes
(cherry picked from commit 9a6b5b9d099eb25aafc26fbf17c27fd32ad4b5ef)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/replsettest_checks_wait_for_secondaries.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/jstests/replsets/replsettest_checks_wait_for_secondaries.js b/jstests/replsets/replsettest_checks_wait_for_secondaries.js
new file mode 100644
index 00000000000..861f038b8f1
--- /dev/null
+++ b/jstests/replsets/replsettest_checks_wait_for_secondaries.js
@@ -0,0 +1,51 @@
+/**
+ * Tests that ReplSetTest consistency checks, namely checkDBHashesForReplSet and
+ * checkCollectionCounts, wait for secondaries to have fully transitioned to SECONDARY state before
+ * attempting data reads.
+ */
+(function() {
+"use strict";
+load("jstests/libs/fail_point_util.js");
+
+const testName = jsTestName();
+const dbName = "testdb";
+const collName = "testcoll";
+
+const rst = new ReplSetTest({name: testName, nodes: 1});
+rst.startSet();
+rst.initiateWithHighElectionTimeout();
+
+const primary = rst.getPrimary();
+const primaryDb = primary.getDB(dbName);
+const primaryColl = primaryDb.getCollection(collName);
+
+assert.commandWorked(primaryColl.insert({"starting": "doc"}));
+
+jsTestLog("Adding a new node to the replica set");
+const secondaryParams = {
+ 'failpoint.initialSyncHangBeforeCopyingDatabases': tojson({mode: 'alwaysOn'}),
+ 'numInitialSyncAttempts': 1,
+};
+const secondary = rst.add({rsConfig: {priority: 0}, setParameter: secondaryParams});
+rst.reInitiate();
+
+jsTestLog("Waiting for node to reach initial sync");
+assert.commandWorked(secondary.adminCommand({
+ waitForFailPoint: "initialSyncHangBeforeCopyingDatabases",
+ timesEntered: 1,
+ maxTimeMS: kDefaultWaitForFailPointTimeout
+}));
+
+// Turn off the failpoint and immediately proceeed with collection counts checks.
+jsTestLog("Trying checkCollectionCounts");
+assert.commandWorked(secondary.adminCommand(
+ {configureFailPoint: "initialSyncHangBeforeCopyingDatabases", mode: "off"}));
+rst.checkCollectionCounts();
+
+// Restart the node so we can try checkReplicatedDBHashes.
+rst.stop(1);
+rst.start(1, {startClean: true});
+
+// stopSet() will call checkReplicatedDBHashes
+rst.stopSet();
+})(); \ No newline at end of file