summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js3
-rw-r--r--jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js3
-rw-r--r--jstests/replsets/initial_sync_fails_after_source_resyncs.js11
-rw-r--r--jstests/replsets/resync_majority_member.js3
-rw-r--r--jstests/sharding/shard_kill_and_pooling.js6
-rw-r--r--src/mongo/shell/replsettest.js12
-rw-r--r--src/mongo/shell/servers.js7
7 files changed, 35 insertions, 10 deletions
diff --git a/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js b/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js
index 48b7ca36961..870a17af3b6 100644
--- a/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js
+++ b/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js
@@ -60,7 +60,8 @@ rst.awaitReplication();
let primaryDbpath = rst.getPrimary().dbpath;
let primaryPort = rst.getPrimary().port;
-rst.stopSet(9, true, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
+rst.stop(0, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}, {forRestart: true});
+rst.stopSet(undefined, true);
// This should succeed in rebuilding the indexes, but only after the databases have been
// repaired.
diff --git a/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js b/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js
index 150d4ca2b64..1be8b066046 100644
--- a/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js
+++ b/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js
@@ -51,7 +51,8 @@ nodes.forEach(node => assert.commandWorked(node.adminCommand(
coll = rst.getPrimary().getDB("indexRebuild")["coll"];
assert.commandWorked(coll.dropIndexes());
rst.awaitReplication();
-rst.stopSet(9, true, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
+rst.stop(0, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}, {forRestart: true});
+rst.stop(1, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}, {forRestart: true});
// Restarting the replica set should rebuild both indexes on both nodes. Just to be dropped
// again by replication recovery. Starting up successfully is a passing test run.
diff --git a/jstests/replsets/initial_sync_fails_after_source_resyncs.js b/jstests/replsets/initial_sync_fails_after_source_resyncs.js
index f2ff6f92394..62672cac27d 100644
--- a/jstests/replsets/initial_sync_fails_after_source_resyncs.js
+++ b/jstests/replsets/initial_sync_fails_after_source_resyncs.js
@@ -81,8 +81,19 @@ assert.commandWorked(initialSyncNodeDb.adminCommand(
assert.commandWorked(initialSyncSource.getDB("admin").adminCommand(
{configureFailPoint: "initialSyncHangBeforeFinish", mode: "off"}));
+// We want to ensure the initialSyncNode encounters the InitialSyncFailure error and shuts down.
+assert.soon(() => {
+ try {
+ initialSyncNodeDb.runCommand({ping: 1});
+ } catch (e) {
+ return true;
+ }
+ return false;
+}, "Node did not shutdown due to initial sync failure", ReplSetTest.kDefaultTimeoutMS);
+
// We skip validation and dbhashes because the initial sync failed so the initial sync node is
// invalid and unreachable.
TestData.skipCheckDBHashes = true;
+rst.stop(initialSyncNode, null, {skipValidation: true, allowedExitCode: MongoRunner.EXIT_ABRUPT});
rst.stopSet(null, null, {skipValidation: true});
})();
diff --git a/jstests/replsets/resync_majority_member.js b/jstests/replsets/resync_majority_member.js
index 29d1e0c921e..4ab48f043ea 100644
--- a/jstests/replsets/resync_majority_member.js
+++ b/jstests/replsets/resync_majority_member.js
@@ -104,5 +104,8 @@ resyncNode.setSlaveOk();
assert.eq(0, syncSource.getDB(dbName)[collName].find(disappearingDoc).itcount());
assert.eq(0, resyncNode.getDB(dbName)[collName].find(disappearingDoc).itcount());
+// We expect node 1 to have crashed.
+const exitCode = _isWindows() ? MongoRunner.EXIT_ABRUPT : MongoRunner.EXIT_ABORT;
+rst.stop(0, undefined, {allowedExitCode: exitCode});
rst.stopSet();
})(); \ No newline at end of file
diff --git a/jstests/sharding/shard_kill_and_pooling.js b/jstests/sharding/shard_kill_and_pooling.js
index 70f36df99a1..4fb49741a1c 100644
--- a/jstests/sharding/shard_kill_and_pooling.js
+++ b/jstests/sharding/shard_kill_and_pooling.js
@@ -56,8 +56,10 @@ for (var test = 0; test < 2; test++) {
var exitCode = killWith === 9 ? MongoRunner.EXIT_SIGKILL : MongoRunner.EXIT_CLEAN;
- st.rs0.stopSet(killWith, true, {allowedExitCode: exitCode});
-
+ for (let node of st.rs0.nodes) {
+ st.rs0.stop(
+ st.rs0.getNodeId(node), killWith, {allowedExitCode: exitCode}, {forRestart: true});
+ }
jsTest.log("Restart shard...");
st.rs0.startSet({forceLock: true}, true);
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index dba8661a089..50ec315bba6 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -3108,7 +3108,8 @@ var ReplSetTest = function(opts) {
};
/**
- * Stops a particular node or nodes, specified by conn or id
+ * Stops a particular node or nodes, specified by conn or id. If we expect the node to exit with
+ * a nonzero exit code, call this function and pass in allowedExitCode as a field of opts.
*
* If _useBridge=true, then the mongobridge process(es) corresponding to the node(s) are also
* terminated unless forRestart=true. The mongobridge process(es) are left running across
@@ -3176,7 +3177,9 @@ var ReplSetTest = function(opts) {
};
/**
- * Kill all members of this replica set.
+ * Kill all members of this replica set. When calling this function, we expect all live nodes to
+ * exit cleanly. If we expect a node to exit with a nonzero exit code, use the stop function to
+ * terminate that node before calling stopSet.
*
* @param {number} signal The signal number to use for killing the members
* @param {boolean} forRestart will not cleanup data directory
@@ -3269,6 +3272,11 @@ var ReplSetTest = function(opts) {
let port = parseInt(conn.port);
print("ReplSetTest stopSet waiting for mongo program on port " + port + " to stop.");
let exitCode = waitMongoProgram(port);
+ if (exitCode !== MongoRunner.EXIT_CLEAN) {
+ throw new Error("ReplSetTest stopSet mongo program on port " + port +
+ " shut down unexpectedly with code " + exitCode + " when code " +
+ MongoRunner.EXIT_CLEAN + " was expected.");
+ }
print("ReplSetTest stopSet mongo program on port " + port + " shut down with code " +
exitCode);
}
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 93f5f4a1c73..8cfb437f365 100644
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -1024,10 +1024,9 @@ var stopMongoProgram = function(conn, signal, opts, waitpid) {
TestData.skipEnforceFastCountOnValidate = true;
}
- var allowedExitCode = MongoRunner.EXIT_CLEAN;
-
- if (opts.allowedExitCode) {
- allowedExitCode = opts.allowedExitCode;
+ const allowedExitCode = opts.allowedExitCode ? opts.allowedExitCode : MongoRunner.EXIT_CLEAN;
+ if (!waitpid && allowedExitCode !== MongoRunner.EXIT_CLEAN) {
+ throw new Error('Must wait for process to exit if it is expected to exit uncleanly');
}
var port = parseInt(conn.port);