summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2017-05-19 13:56:45 -0400
committerWilliam Schultz <william.schultz@mongodb.com>2017-06-22 15:23:23 -0400
commit3221f3ffcaf29ed36ce59453637321bdbd2a1fed (patch)
treedd8b35452bea73c4d53d3b10bb578ee538e5ea21
parente9ad6a777d762fdae1d54137f7c8fae69784fc2a (diff)
downloadmongo-3221f3ffcaf29ed36ce59453637321bdbd2a1fed.tar.gz
SERVER-28378 Extend secondary catch up period in priority_takeover_two_nodes_equal_priority.js
(cherry picked from commit 344de09ffc51bbc7786269917ebd1b417b940a7a)
-rw-r--r--jstests/replsets/priority_takeover_two_nodes_equal_priority.js62
1 files changed, 32 insertions, 30 deletions
diff --git a/jstests/replsets/priority_takeover_two_nodes_equal_priority.js b/jstests/replsets/priority_takeover_two_nodes_equal_priority.js
index 42134f9430e..10f31796b2a 100644
--- a/jstests/replsets/priority_takeover_two_nodes_equal_priority.js
+++ b/jstests/replsets/priority_takeover_two_nodes_equal_priority.js
@@ -1,25 +1,29 @@
-// 2 nodes with non-default priority.
-// 3-node replica set with priorities 3, 3 and 1 (default)
-// Start replica set. Ensure that highest priority node becomes primary eventually.
-// Step down the primary and confirm that the next highest priority node becomes primary.
+/**
+ * Test to ensure that nodes with the highest priorities eventually become PRIMARY.
+ *
+ * 1. Initiate a 3 node replica set with node priorities of 3, 3 and 1 (default)
+ * 2. Make sure that one of the highest priority nodes becomes PRIMARY.
+ * 3. Step down the PRIMARY and confirm that the other high priority node becomes PRIMARY.
+ */
load('jstests/replsets/rslib.js');
(function() {
'use strict';
var name = 'priority_takeover_two_nodes_equal_priority';
- var replSet = new ReplSetTest(
- {name: name, nodes: [{rsConfig: {priority: 3}}, {rsConfig: {priority: 3}}, {}, ]});
- replSet.startSet();
- replSet.initiate();
+ var replTest = new ReplSetTest(
+ {name: name, nodes: [{rsConfig: {priority: 3}}, {rsConfig: {priority: 3}}, {}]});
+ replTest.startSet();
+ replTest.initiate();
+ jsTestLog("Waiting for one of the high priority nodes to become PRIMARY.");
var primary;
var primaryIndex = -1;
var defaultPriorityNodeIndex = 2;
assert.soon(
function() {
- primary = replSet.getPrimary();
- replSet.nodes.find(function(node, index, array) {
+ primary = replTest.getPrimary();
+ replTest.nodes.find(function(node, index, array) {
if (primary.host == node.host) {
primaryIndex = index;
return true;
@@ -28,27 +32,25 @@ load('jstests/replsets/rslib.js');
});
return primaryIndex !== defaultPriorityNodeIndex;
},
- 'neither of the priority 3 nodes was elected primary',
- 60000, // timeout
- 1000 // interval
+ 'Neither of the high priority nodes was elected primary.',
+ replTest.kDefaultTimeoutMS, // timeout
+ 1000 // interval
);
- try {
- assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 90}));
- } catch (x) {
- // expected
- }
- var newPrimaryIndex = primaryIndex === 0 ? 1 : 0;
-
- // Refresh connections to nodes.
- replSet.status();
-
- assert.commandWorked(replSet.nodes[newPrimaryIndex].adminCommand({
- replSetTest: 1,
- waitForMemberState: ReplSetTest.State.PRIMARY,
- timeoutMillis: 60 * 1000,
- }),
- 'node ' + newPrimaryIndex + ' ' + replSet.nodes[newPrimaryIndex].host +
- ' failed to become primary');
+ jsTestLog("Stepping down the current primary.");
+ assert.throws(function() {
+ assert.commandWorked(
+ primary.adminCommand({replSetStepDown: 10 * 60, secondaryCatchUpPeriodSecs: 10 * 60}));
+ });
+
+ // Make sure the primary has stepped down.
+ assert.neq(primary, replTest.getPrimary());
+
+ // We expect the other high priority node to eventually become primary.
+ var expectedNewPrimaryIndex = (primaryIndex === 0) ? 1 : 0;
+
+ jsTestLog("Waiting for the other high priority node to become PRIMARY.");
+ var expectedNewPrimary = replTest.nodes[expectedNewPrimaryIndex];
+ replTest.waitForState(expectedNewPrimary, ReplSetTest.State.PRIMARY);
})();