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-05 17:51:44 +0000 |
commit | 93a75ad40b00da1d30e5d01c26afda1488c9edf2 (patch) | |
tree | 4cb85c127f2fe3163d8cf60006a8cbd59f91655a /jstests/replsets/change_stream_stepdown.js | |
parent | ad5ca87b55d7c41827f8e61d22b18aa222b1ef6e (diff) | |
download | mongo-93a75ad40b00da1d30e5d01c26afda1488c9edf2.tar.gz |
SERVER-48576 Fix the election race in change_stream_stepdown.js
Diffstat (limited to 'jstests/replsets/change_stream_stepdown.js')
-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"); |