diff options
author | Suganthi Mani <suganthi.mani@mongodb.com> | 2020-06-03 17:53:46 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-15 14:44:34 +0000 |
commit | f49d921229da2c28dec04b70f2c780cd7e229b5b (patch) | |
tree | 50724720aeb045bf0782dc205b03e3de13016c13 | |
parent | e4be1b7d5e23018957c0d0301a0f62ee651c7082 (diff) | |
download | mongo-f49d921229da2c28dec04b70f2c780cd7e229b5b.tar.gz |
SERVER-48576 Fix the election race in change_stream_stepdown.js
(cherry picked from commit 93a75ad40b00da1d30e5d01c26afda1488c9edf2)
-rw-r--r-- | jstests/replsets/change_stream_stepdown.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/jstests/replsets/change_stream_stepdown.js b/jstests/replsets/change_stream_stepdown.js index 1a6f6fb28cb..518b15166ee 100644 --- a/jstests/replsets/change_stream_stepdown.js +++ b/jstests/replsets/change_stream_stepdown.js @@ -12,7 +12,16 @@ load("jstests/libs/write_concern_util.js"); // for [stop|restart]ServerReplicat const name = "change_stream_stepdown"; const replTest = new ReplSetTest({name: name, nodes: [{}, {}]}); replTest.startSet(); -replTest.initiate(); +// Initiate with high election timeout to prevent any election races. +replTest.initiateWithHighElectionTimeout(); + +function stepUp(conn) { + assert.commandWorked(conn.adminCommand({replSetFreeze: 0})); + assert.commandWorked(conn.adminCommand({replSetStepUp: 1, skipDryRun: true})); + + // Waits for the new primary to accept new writes. + return replTest.getPrimary(); +} const dbName = name; const collName = "change_stream_stepdown"; @@ -24,9 +33,6 @@ const primaryDb = primary.getDB(dbName); const secondaryDb = secondary.getDB(dbName); const primaryColl = primaryDb[collName]; -// Tell the secondary to stay secondary until we say otherwise. -assert.commandWorked(secondaryDb.adminCommand({replSetFreeze: 999999})); - // Open a change stream. let res = primaryDb.runCommand({ aggregate: collName, @@ -58,8 +64,7 @@ assert.eq(changes[0]["operationType"], "insert"); jsTestLog("Testing that changestream survives step-up"); // Step back up and wait for primary. -assert.commandWorked(primaryDb.adminCommand({replSetFreeze: 0})); -replTest.getPrimary(); +stepUp(primary); // Get the next one. This tests that changestreams survives a step-up. res = assert.commandWorked( @@ -83,8 +88,7 @@ assert.eq(changes[0]["fullDocument"], {_id: 3}); assert.eq(changes[0]["operationType"], "insert"); // Step back up and wait for primary. -assert.commandWorked(primaryDb.adminCommand({replSetFreeze: 0})); -replTest.getPrimary(); +stepUp(primary); jsTestLog("Testing that changestream waiting on old primary sees docs inserted on new primary"); |