summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2019-02-07 15:52:06 -0500
committerMatthew Russotto <matthew.russotto@10gen.com>2019-02-12 11:07:46 -0500
commit77dccdfdc54eab46031f465a2e46570cc5c3c52f (patch)
tree9c7b1449f6dedd7076256d314aee52637445f43c
parentc3a72d61dc8ab4aa32fae400c74b06360a572537 (diff)
downloadmongo-77dccdfdc54eab46031f465a2e46570cc5c3c52f.tar.gz
SERVER-38516 Tighten up tests that don't fail when not closing connections during stepdown bbut allow exceptions during stepdown
-rw-r--r--jstests/libs/csrs_upgrade_util.js7
-rw-r--r--jstests/replsets/background_index.js6
-rw-r--r--jstests/replsets/catchup.js7
-rw-r--r--jstests/replsets/dbcheck.js8
-rw-r--r--jstests/replsets/drop_collections_two_phase_step_down.js13
-rw-r--r--jstests/replsets/get_replication_info_helper.js5
-rw-r--r--jstests/replsets/initial_sync_during_stepdown.js1
-rw-r--r--jstests/replsets/libs/election_handoff.js6
-rw-r--r--jstests/replsets/libs/rollback_test_deluxe.js3
-rw-r--r--jstests/replsets/reconfig_during_election.js6
-rw-r--r--jstests/replsets/replset3.js8
-rw-r--r--jstests/replsets/replsetfreeze.js14
-rw-r--r--jstests/replsets/restore_term.js7
-rw-r--r--jstests/replsets/rollback_via_refetch_commit_transaction.js7
-rw-r--r--jstests/replsets/rollback_with_socket_error_then_steady_state.js7
-rw-r--r--jstests/replsets/step_down_during_draining3.js8
-rw-r--r--jstests/replsets/stepdown_kill_other_ops.js6
-rw-r--r--jstests/replsets/temp_namespace.js6
-rw-r--r--jstests/sharding/move_chunk_with_session_helper.js7
19 files changed, 35 insertions, 97 deletions
diff --git a/jstests/libs/csrs_upgrade_util.js b/jstests/libs/csrs_upgrade_util.js
index 76eddf3e0b5..8a4b3582f9f 100644
--- a/jstests/libs/csrs_upgrade_util.js
+++ b/jstests/libs/csrs_upgrade_util.js
@@ -158,10 +158,7 @@ var CSRSUpgradeCoordinator = function() {
this.switchToCSRSMode = function() {
jsTest.log("Restarting " + csrs[0].name + " in csrs mode");
delete csrs0Opts.configsvrMode;
- try {
- csrs[0].adminCommand({replSetStepDown: 60});
- } catch (e) {
- } // Expected
+ assert.commandWorked(csrs[0].adminCommand({replSetStepDown: 60}));
MongoRunner.stopMongod(csrs[0]);
csrs[0] = MongoRunner.runMongod(csrs0Opts);
var csrsStatus;
@@ -208,4 +205,4 @@ var CSRSUpgradeCoordinator = function() {
MongoRunner.stopMongod(st.c1);
};
-}; \ No newline at end of file
+};
diff --git a/jstests/replsets/background_index.js b/jstests/replsets/background_index.js
index 6d891a66a85..e92530bc985 100644
--- a/jstests/replsets/background_index.js
+++ b/jstests/replsets/background_index.js
@@ -33,11 +33,7 @@
rst.awaitReplication();
// Step down the primary.
- try {
- adminDB.runCommand({replSetStepDown: 60, force: true});
- } catch (e) {
- // Left empty on purpose.
- }
+ assert.commandWorked(adminDB.runCommand({replSetStepDown: 60, force: true}));
// Wait for new primary.
var newPrimary = rst.getPrimary();
diff --git a/jstests/replsets/catchup.js b/jstests/replsets/catchup.js
index 82d542e9bbd..b93cd78cff1 100644
--- a/jstests/replsets/catchup.js
+++ b/jstests/replsets/catchup.js
@@ -190,11 +190,8 @@
var stepUpResults = stopReplicationAndEnforceNewPrimaryToCatchUp();
// Step-down command should abort catchup.
- try {
- printjson(stepUpResults.newPrimary.adminCommand({replSetStepDown: 60}));
- } catch (e) {
- print(e);
- }
+ assert.commandWorked(stepUpResults.newPrimary.adminCommand({replSetStepDown: 60}));
+
// Rename the primary.
var steppedDownPrimary = stepUpResults.newPrimary;
var newPrimary = rst.getPrimary();
diff --git a/jstests/replsets/dbcheck.js b/jstests/replsets/dbcheck.js
index c574e42a5a6..07b268bb0ec 100644
--- a/jstests/replsets/dbcheck.js
+++ b/jstests/replsets/dbcheck.js
@@ -313,12 +313,8 @@
let nodeId = replSet.getNodeId(master);
assert.commandWorked(db.runCommand({dbCheck: multiBatchSimpleCollName}));
- // Step down the master. This will close our connection.
- try {
- master.getDB("admin").runCommand({replSetStepDown: 0, force: true});
- // (throwing an exception in the process, which we will ignore).
- } catch (e) {
- }
+ // Step down the master.
+ assert.commandWorked(master.getDB("admin").runCommand({replSetStepDown: 0, force: true}));
// Wait for the cluster to come up.
replSet.awaitSecondaryNodes();
diff --git a/jstests/replsets/drop_collections_two_phase_step_down.js b/jstests/replsets/drop_collections_two_phase_step_down.js
index bc2f4c58909..5d67d60e73a 100644
--- a/jstests/replsets/drop_collections_two_phase_step_down.js
+++ b/jstests/replsets/drop_collections_two_phase_step_down.js
@@ -48,14 +48,9 @@
// Force step down primary.
jsTestLog('Stepping down primary ' + primary.host + ' with {force: true}.');
- const stepDownResult = assert.throws(function() {
- // The amount of time the node has to wait before becoming primary again.
- const stepDownSecs = 1;
- primary.adminCommand({replSetStepDown: stepDownSecs, force: true});
- });
- let errMsg = 'Expected exception from stepping down primary ' + primary.host + ': ' +
- tojson(stepDownResult);
- assert(isNetworkError(stepDownResult), errMsg);
+ // The amount of time the node has to wait before becoming primary again.
+ const stepDownSecs = 1;
+ assert.commandWorked(primary.adminCommand({replSetStepDown: stepDownSecs, force: true}));
// Wait for the node that stepped down to regain PRIMARY status.
jsTestLog('Waiting for node ' + primary.host + ' to become primary again');
@@ -72,4 +67,4 @@
} finally {
twoPhaseDropTest.stop();
}
-}()); \ No newline at end of file
+}());
diff --git a/jstests/replsets/get_replication_info_helper.js b/jstests/replsets/get_replication_info_helper.js
index 0fed84db2c4..5e2a696bb80 100644
--- a/jstests/replsets/get_replication_info_helper.js
+++ b/jstests/replsets/get_replication_info_helper.js
@@ -38,10 +38,7 @@
var secondary = replSet._slaves[i];
secondary.getDB('admin').runCommand({replSetFreeze: 120});
}
- try {
- primary.getDB('admin').runCommand({replSetStepDown: 120, force: true});
- } catch (e) {
- }
+ assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 120, force: true}));
mongo =
startParallelShell("db.getSiblingDB('admin').printSlaveReplicationInfo();", primary.port);
diff --git a/jstests/replsets/initial_sync_during_stepdown.js b/jstests/replsets/initial_sync_during_stepdown.js
index 5b8f9ad3b11..e407ca3da48 100644
--- a/jstests/replsets/initial_sync_during_stepdown.js
+++ b/jstests/replsets/initial_sync_during_stepdown.js
@@ -61,7 +61,6 @@
jsTestLog("Making primary step down");
const joinStepDownThread = startParallelShell(() => {
-
assert.commandWorked(db.adminCommand({"replSetStepDown": 30 * 60, "force": true}));
}, primary.port);
diff --git a/jstests/replsets/libs/election_handoff.js b/jstests/replsets/libs/election_handoff.js
index 6bb903c1b2c..58e464a14c6 100644
--- a/jstests/replsets/libs/election_handoff.js
+++ b/jstests/replsets/libs/election_handoff.js
@@ -50,10 +50,10 @@ var ElectionHandoffTest = (function() {
rst.awaitNodesAgreeOnAppliedOpTime();
// Step down the current primary.
- assert.adminCommandWorkedAllowingNetworkError(primary, {
+ assert.commandWorked(primary.adminCommand({
replSetStepDown: kStepDownPeriodSecs,
secondaryCatchUpPeriodSecs: kStepDownPeriodSecs / 2
- });
+ }));
jsTestLog(`Checking that the secondary with id ${expectedCandidateId} is stepped up...`);
@@ -77,4 +77,4 @@ var ElectionHandoffTest = (function() {
return {testElectionHandoff: testElectionHandoff, stepDownPeriodSecs: kStepDownPeriodSecs};
-})(); \ No newline at end of file
+})();
diff --git a/jstests/replsets/libs/rollback_test_deluxe.js b/jstests/replsets/libs/rollback_test_deluxe.js
index b3b85de152d..0c1d05579b9 100644
--- a/jstests/replsets/libs/rollback_test_deluxe.js
+++ b/jstests/replsets/libs/rollback_test_deluxe.js
@@ -427,8 +427,7 @@ function RollbackTestDeluxe(name = "FiveNodeDoubleRollbackTest", replSet) {
sb.push(currentRolesToString());
log(`Forcing the primary ${curPrimary.host} to step down`, true);
- assert.adminCommandWorkedAllowingNetworkError(curPrimary,
- {replSetStepDown: 1, force: true});
+ assert.commandWorked(curPrimary.adminCommand({replSetStepDown: 1, force: true}));
waitForState(curPrimary, ReplSetTest.State.SECONDARY);
log(`Waiting for the rollback secondary ${rollbackSecondary.host} to be elected`);
diff --git a/jstests/replsets/reconfig_during_election.js b/jstests/replsets/reconfig_during_election.js
index 4f58b3cd477..aaf33c8ac67 100644
--- a/jstests/replsets/reconfig_during_election.js
+++ b/jstests/replsets/reconfig_during_election.js
@@ -26,10 +26,10 @@
}));
// The incumbent sends replSetStepUp to the candidate for election handoff.
- assert.adminCommandWorkedAllowingNetworkError(incumbent, {
+ assert.commandWorked(incumbent.adminCommand({
replSetStepDown: ElectionHandoffTest.stepDownPeriodSecs,
secondaryCatchUpPeriodSecs: ElectionHandoffTest.stepDownPeriodSecs / 2
- });
+ }));
jsTestLog("Wait for candidate to win the election");
@@ -46,4 +46,4 @@
{configureFailPoint: "electionHangsBeforeUpdateMemberState", mode: "off"}));
rst.stopSet();
-})(); \ No newline at end of file
+})();
diff --git a/jstests/replsets/replset3.js b/jstests/replsets/replset3.js
index 7f6f9505cc3..ee12d75a0bb 100644
--- a/jstests/replsets/replset3.js
+++ b/jstests/replsets/replset3.js
@@ -25,12 +25,8 @@ var doTest = function(signal) {
print(phase++);
- // Step down master. Note: this will close our connection!
- try {
- master.getDB("admin").runCommand({replSetStepDown: 0, force: 1});
- } catch (err) {
- print("caught: " + err + " on stepdown");
- }
+ // Step down master.
+ assert.commandWorked(master.getDB("admin").runCommand({replSetStepDown: 0, force: 1}));
print(phase++);
diff --git a/jstests/replsets/replsetfreeze.js b/jstests/replsets/replsetfreeze.js
index 8093d950aad..a9b3fdc85ba 100644
--- a/jstests/replsets/replsetfreeze.js
+++ b/jstests/replsets/replsetfreeze.js
@@ -67,12 +67,7 @@ assert.commandFailedWithCode(
'replSetFreeze should return error when run on primary ' + master.host);
jsTestLog('3: step down primary ' + master.host);
-try {
- master.getDB("admin").runCommand({replSetStepDown: 10, force: 1});
-} catch (e) {
- print(e);
-}
-reconnect(master);
+assert.commandWorked(master.getDB("admin").runCommand({replSetStepDown: 10, force: 1}));
printjson(master.getDB("admin").runCommand({replSetGetStatus: 1}));
jsTestLog('4: freeze stepped down primary ' + master.host + ' for 30 seconds');
@@ -95,12 +90,7 @@ assert.eq(master.host,
'new primary should be the same node as primary that previously stepped down');
jsTestLog('7: step down new master ' + master.host);
-try {
- master.getDB("admin").runCommand({replSetStepDown: 10, force: 1});
-} catch (e) {
- jsTestLog('step down command threw exception' + e);
-}
-reconnect(master);
+assert.commandWorked(master.getDB("admin").runCommand({replSetStepDown: 10, force: 1}));
jsTestLog('8: freeze stepped down primary ' + master.host + ' for 30 seconds');
master.getDB("admin").runCommand({replSetFreeze: 30});
diff --git a/jstests/replsets/restore_term.js b/jstests/replsets/restore_term.js
index 1eabd276c83..05c03a2dfee 100644
--- a/jstests/replsets/restore_term.js
+++ b/jstests/replsets/restore_term.js
@@ -40,11 +40,8 @@ load("jstests/replsets/rslib.js");
assert.eq(latestOp.t, firstSuccessfulTerm);
// Step down to increase the term.
- try {
- var res = primary.adminCommand({replSetStepDown: 0});
- } catch (err) {
- print("caught: " + err + " on stepdown");
- }
+ assert.commandWorked(primary.adminCommand({replSetStepDown: 0}));
+
rst.awaitSecondaryNodes();
// The secondary became the new primary now with a higher term.
// Since there's only one secondary who may run for election, the new term is higher by 1.
diff --git a/jstests/replsets/rollback_via_refetch_commit_transaction.js b/jstests/replsets/rollback_via_refetch_commit_transaction.js
index 7037959e10a..51ff943435c 100644
--- a/jstests/replsets/rollback_via_refetch_commit_transaction.js
+++ b/jstests/replsets/rollback_via_refetch_commit_transaction.js
@@ -67,10 +67,11 @@
// Issue an explicit stepdown command to save us some of the wait.
try {
- rollbackNode.adminCommand({replSetStepDown: 60, force: true});
+ assert.commandWorked(rollbackNode.adminCommand({replSetStepDown: 60, force: true}));
} catch (e) {
- // Stepdown may fail if the node has already started stepping down. We might also
- // get an exception when the node closes the connection. Both are acceptable.
+ // Stepdown may fail if the node has already started stepping down.
+ if (!ErrorCodes.isNotMasterError(e))
+ throw e;
print('Caught exception from replSetStepDown: ' + e);
}
diff --git a/jstests/replsets/rollback_with_socket_error_then_steady_state.js b/jstests/replsets/rollback_with_socket_error_then_steady_state.js
index c2be45aa969..29f060757d1 100644
--- a/jstests/replsets/rollback_with_socket_error_then_steady_state.js
+++ b/jstests/replsets/rollback_with_socket_error_then_steady_state.js
@@ -32,12 +32,7 @@
function stepUp(rst, node) {
var primary = rst.getPrimary();
if (primary != node) {
- try {
- assert.commandWorked(primary.adminCommand({replSetStepDown: 1, force: true}));
- } catch (ex) {
- print("Caught exception while stepping down from node '" + tojson(node.host) +
- "': " + tojson(ex));
- }
+ assert.commandWorked(primary.adminCommand({replSetStepDown: 1, force: true}));
}
waitForState(node, ReplSetTest.State.PRIMARY);
}
diff --git a/jstests/replsets/step_down_during_draining3.js b/jstests/replsets/step_down_during_draining3.js
index 775e5563195..c8631bd12f1 100644
--- a/jstests/replsets/step_down_during_draining3.js
+++ b/jstests/replsets/step_down_during_draining3.js
@@ -99,15 +99,9 @@
ErrorCodes.ExceededTimeLimit,
'replSetTest waitForDrainFinish should time out when draining is not allowed to complete');
- try {
- secondary.adminCommand({replSetStepDown: 60, force: true});
- } catch (e) {
- // expected
- print("Caught stepdown exception: " + tojson(e));
- }
+ assert.commandWorked(secondary.adminCommand({replSetStepDown: 60, force: true}));
// Assert stepdown was successful.
- reconnect(secondary);
assert.eq(ReplSetTest.State.SECONDARY, secondary.adminCommand({replSetGetStatus: 1}).myState);
assert(!secondary.adminCommand('ismaster').ismaster);
diff --git a/jstests/replsets/stepdown_kill_other_ops.js b/jstests/replsets/stepdown_kill_other_ops.js
index a3de1e909b2..1dc2404b8e4 100644
--- a/jstests/replsets/stepdown_kill_other_ops.js
+++ b/jstests/replsets/stepdown_kill_other_ops.js
@@ -51,11 +51,7 @@
}, "sleep never ran and grabbed the global write lock");
jsTestLog("Stepping down");
- try {
- assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 30}));
- } catch (x) {
- // expected
- }
+ assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 30}));
jsTestLog("Waiting for former PRIMARY to become SECONDARY");
replSet.waitForState(primary, ReplSetTest.State.SECONDARY, 30000);
diff --git a/jstests/replsets/temp_namespace.js b/jstests/replsets/temp_namespace.js
index 32aca2eedf0..678922f9501 100644
--- a/jstests/replsets/temp_namespace.js
+++ b/jstests/replsets/temp_namespace.js
@@ -81,11 +81,7 @@ assert.eq(countIndexesFor(secondDB, /temp\d$/), 4); // indexes (2 _id + 2 x)
assert.eq(countCollection(secondDB, /keep\d$/), 4);
// step down primary and make sure former secondary (now primary) drops collections
-try {
- master.adminCommand({replSetStepDown: 50, force: true});
-} catch (e) {
- // ignoring socket errors since they sometimes, but not always, fire after running that command.
-}
+assert.commandWorked(master.adminCommand({replSetStepDown: 50, force: true}));
assert.soon(function() {
return secondDB.isMaster().ismaster;
diff --git a/jstests/sharding/move_chunk_with_session_helper.js b/jstests/sharding/move_chunk_with_session_helper.js
index 6728a245bbe..bf4653eb18a 100644
--- a/jstests/sharding/move_chunk_with_session_helper.js
+++ b/jstests/sharding/move_chunk_with_session_helper.js
@@ -27,11 +27,8 @@ var testMoveChunkWithSession = function(
checkRetryResultFunc(result, assert.commandWorked(testDB.runCommand(cmdObj)));
checkDocumentsFunc(coll);
- try {
- st.rs1.getPrimary().adminCommand({replSetStepDown: 60, secondaryCatchUpPeriodSecs: 30});
- } catch (excep) {
- print('Expected exception due to step down: ' + tojson(excep));
- }
+ assert.commandWorked(
+ st.rs1.getPrimary().adminCommand({replSetStepDown: 60, secondaryCatchUpPeriodSecs: 30}));
st.rs1.awaitNodesAgreeOnPrimary();
st.configRS.nodes.concat([st.s]).forEach(function awaitNode(conn) {