diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2016-12-14 13:18:59 -0500 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2016-12-14 13:18:59 -0500 |
commit | 232832a0e79252a29061def2fb89b985f29b78c7 (patch) | |
tree | 9c0bcbb3fc85ffd6ad7cfd4ddcd667d19a999177 /jstests/replsets/shutdown_primary.js | |
parent | c97cdf0f56c13463c3df0448ebeff812c06d1259 (diff) | |
download | mongo-232832a0e79252a29061def2fb89b985f29b78c7.tar.gz |
SERVER-27118 Default shutdown command's timeoutSecs argument to 10 seconds
Diffstat (limited to 'jstests/replsets/shutdown_primary.js')
-rw-r--r-- | jstests/replsets/shutdown_primary.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/jstests/replsets/shutdown_primary.js b/jstests/replsets/shutdown_primary.js new file mode 100644 index 00000000000..0192bc41b49 --- /dev/null +++ b/jstests/replsets/shutdown_primary.js @@ -0,0 +1,62 @@ +/** + * Test that the shutdown command called on a primary node waits for a majority of secondaries to + * catch up before taking effect, and will fail otherwise. + * + * 1. Initiate a 3-node replica set + * 2. Block replication to secondaries + * 3. Write to primary + * 4. Try to shut down primary and expect failure + * 5. Try to shut down primary in a parallel shell and expect success + * 6. Resume replication on secondaries + * 7. Try to create a new connection to the shut down primary and expect an error + * + */ +(function() { + load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries, + // restartReplSetReplication + + "use strict"; + + var name = "shutdown_primary"; + + var replTest = new ReplSetTest({name: name, nodes: 3}); + replTest.startSet(); + replTest.initiate(); + + var primary = replTest.getPrimary(); + var testDB = primary.getDB(name); + var timeout = 5 * 60 * 1000; + assert.writeOK(testDB.foo.insert({x: 1}, {writeConcern: {w: 3, wtimeout: timeout}})); + + jsTestLog("Blocking replication to secondaries."); + stopReplicationOnSecondaries(replTest); + + jsTestLog("Executing write to primary."); + assert.writeOK(testDB.foo.insert({x: 2})); + + jsTestLog("Attempting to shut down primary."); + assert.commandFailedWithCode(primary.adminCommand({shutdown: 1}), + ErrorCodes.ExceededTimeLimit, + "shut down did not fail with 'ExceededTimeLimit'"); + + jsTestLog("Verifying primary did not shut down."); + assert.writeOK(testDB.foo.insert({x: 3})); + + jsTestLog("Shutting down primary in a parallel shell"); + var awaitShell = startParallelShell(function() { + db.adminCommand({shutdown: 1, timeoutSecs: 60}); + }, primary.port); + + jsTestLog("Resuming replication."); + restartReplSetReplication(replTest); + + jsTestLog("Verifying primary shut down and cannot be connected to."); + // Successful shutdown throws network error. + var exitCode = awaitShell({checkExitSuccess: false}); + assert.neq(0, exitCode, "expected shutdown to close the shell's connection"); + assert.throws(function() { + new Mongo(primary.host); + }); + + replTest.stopSet(); +})(); |