diff options
author | William Schultz <william.schultz@mongodb.com> | 2017-04-05 11:33:05 -0400 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2017-04-17 12:12:29 -0400 |
commit | 751ecf3955279a81cb961fe09a6fd5e411f8e29b (patch) | |
tree | b786b103e7a6b0ad0e2f2253b69a5c5dff9b8c44 | |
parent | 8ebe984f0c6cf959d1c9223f836badda742a54d2 (diff) | |
download | mongo-751ecf3955279a81cb961fe09a6fd5e411f8e29b.tar.gz |
SERVER-28480/27966 last_vote.js should await replication and call stepUp before reconfig
(cherry picked from commit 83ea6f6274b6f5f525569e72e278872886a3d70c)
-rw-r--r-- | jstests/replsets/last_vote.js | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/jstests/replsets/last_vote.js b/jstests/replsets/last_vote.js index bf1079884f8..9b05766cae6 100644 --- a/jstests/replsets/last_vote.js +++ b/jstests/replsets/last_vote.js @@ -24,7 +24,7 @@ // Lower the election timeout to make the test run faster since it waits for multiple elections. var conf = rst.getReplSetConfig(); conf.settings = { - electionTimeoutMillis: 3000, + electionTimeoutMillis: 6000, }; rst.initiate(conf); @@ -59,31 +59,42 @@ jsTestLog("Test that last vote is set on successive elections"); - for (var i = 0; i < 3; i++) { + // Run a few successive elections, alternating who becomes primary. + var numElections = 3; + for (var i = 0; i < numElections; i++) { var primary = rst.getPrimary(); + var secondary = rst.getSecondary(); var term = getLatestOp(primary).t; + jsTestLog("Last vote should have term: " + term + " and candidate: " + primary.host + ", index: " + rst.getNodeId(primary)); rst.nodes.forEach(function(node) { assertNodeHasLastVote(node, term, primary); }); + assert.throws(function() { - primary.adminCommand({replSetStepDown: 5, force: true}); + primary.adminCommand({replSetStepDown: 60 * 10, force: true}); }); + + // Make sure a new primary has been established. rst.waitForState(primary, ReplSetTest.State.SECONDARY); + rst.waitForState(secondary, ReplSetTest.State.PRIMARY); + + // Reset election timeout for the old primary. + assert.commandWorked(primary.adminCommand({replSetFreeze: 0})); } var term = getLatestOp(rst.getPrimary()).t + 100; jsTestLog("Test that last vote is loaded on startup"); - // We cannot reconfig nodes[0] to have priority 0 if it is currently the primary. - if (rst.getPrimary() === rst.nodes[0]) { - jsTestLog("Stepping down node 0 before reconfig"); - assert.throws(function() { - rst.nodes[0].adminCommand({replSetStepDown: 5, force: true}); - }); - rst.waitForState(rst.nodes[0], ReplSetTest.State.SECONDARY); - } + + // Ensure that all ops are replicated before stepping up node 1. + rst.awaitReplication(); + + // We cannot reconfig node 0 to have priority 0 if it is currently the primary, + // so we make sure node 1 is primary. + jsTestLog("Stepping up node 1"); + rst.stepUp(rst.nodes[1]); jsTestLog("Reconfiguring cluster to make node 0 unelectable so it stays SECONDARY on restart"); conf = rst.getReplSetConfigFromNode(); |