summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2017-04-05 11:33:05 -0400
committerWilliam Schultz <william.schultz@mongodb.com>2017-04-17 11:36:57 -0400
commit7a6d8274f57cf141fd1d5c754ea1e2a1a6d2f372 (patch)
tree3495292c771ebc13e600e3923133417f7aa50197
parent94c5dff95cbeeb1da7d50738d1ceebe5251f528e (diff)
downloadmongo-7a6d8274f57cf141fd1d5c754ea1e2a1a6d2f372.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.js36
1 files changed, 23 insertions, 13 deletions
diff --git a/jstests/replsets/last_vote.js b/jstests/replsets/last_vote.js
index f087330846e..84a6c206865 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);
@@ -56,35 +56,45 @@
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));
+
// SERVER-20844 ReplSetTest starts up a single node replica set then reconfigures to the
// correct size, so secondaries didn't vote in the first election.
if (i > 0) {
+ 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();