summaryrefslogtreecommitdiff
path: root/jstests/replsets/stepup.js
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2016-05-17 15:43:35 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2016-07-05 16:51:04 -0400
commite3ee305be314d8109ec1f1fd558b7011817dbfe7 (patch)
treeb831be96e3a66c52336d2e4a7ca382e5c8a3206f /jstests/replsets/stepup.js
parent71424c1c4b87c5819b1fc5cf114078a6f33c6078 (diff)
downloadmongo-e3ee305be314d8109ec1f1fd558b7011817dbfe7.tar.gz
SERVER-24881 Add StepUp Command.
Diffstat (limited to 'jstests/replsets/stepup.js')
-rw-r--r--jstests/replsets/stepup.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/jstests/replsets/stepup.js b/jstests/replsets/stepup.js
new file mode 100644
index 00000000000..f772febfe50
--- /dev/null
+++ b/jstests/replsets/stepup.js
@@ -0,0 +1,53 @@
+// Tests the replSetStepUp command.
+
+load("jstests/replsets/rslib.js");
+
+(function() {
+
+ "use strict";
+ var name = "stepup";
+ var rst = new ReplSetTest({name: name, nodes: 2});
+
+ rst.startSet();
+ // Initiate the replset in protocol version 0.
+ var conf = rst.getReplSetConfig();
+ conf.protocolVersion = 0;
+ rst.initiate(conf);
+ rst.awaitReplication();
+
+ var primary = rst.getPrimary();
+ var secondary = rst.getSecondary();
+ var res = secondary.adminCommand({replSetStepUp: 1});
+ assert.commandFailedWithCode(res, ErrorCodes.CommandNotSupported);
+
+ // Upgrade protocol version
+ conf = rst.getReplSetConfigFromNode();
+ conf.protocolVersion = 1;
+ conf.version++;
+ reconfig(rst, conf);
+ // Wait for the upgrade to finish.
+ assert.writeOK(primary.getDB("test").bar.insert({x: 1}, {writeConcern: {w: 2}}));
+
+ // Step up the primary. Return OK because it's already the primary.
+ res = primary.adminCommand({replSetStepUp: 1});
+ assert.commandWorked(res);
+ assert.eq(primary, rst.getPrimary());
+
+ // Step up the secondary, but it's not eligible to be primary.
+ // Enable fail point on secondary.
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'rsSyncApplyStop', mode: 'alwaysOn'}));
+
+ assert.writeOK(primary.getDB("test").bar.insert({x: 2}, {writeConcern: {w: 1}}));
+ res = secondary.adminCommand({replSetStepUp: 1});
+ assert.commandFailedWithCode(res, ErrorCodes.NotMaster);
+ assert.commandWorked(
+ secondary.getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'}));
+
+ // Step up the secondary and succeed.
+ rst.awaitReplication();
+ res = secondary.adminCommand({replSetStepUp: 1});
+ assert.commandWorked(res);
+ assert.eq(secondary, rst.getPrimary());
+
+})();