diff options
author | William Schultz <william.schultz@mongodb.com> | 2017-05-19 13:56:45 -0400 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2017-06-22 15:17:09 -0400 |
commit | 147a9b4b1970510cb4fb28bd2a58576f46b75f76 (patch) | |
tree | e6b8a18d01e433b3d4238f67d395220d25d74906 | |
parent | 5e528ece0ead6ca020ec0be14aa0f080a5265c92 (diff) | |
download | mongo-147a9b4b1970510cb4fb28bd2a58576f46b75f76.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.js | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/jstests/replsets/priority_takeover_two_nodes_equal_priority.js b/jstests/replsets/priority_takeover_two_nodes_equal_priority.js index b6e8cc25b77..10f31796b2a 100644 --- a/jstests/replsets/priority_takeover_two_nodes_equal_priority.js +++ b/jstests/replsets/priority_takeover_two_nodes_equal_priority.js @@ -1,31 +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; @@ -34,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); })(); |