summaryrefslogtreecommitdiff
path: root/jstests/libs
diff options
context:
space:
mode:
authorSamy Lanka <samy.lanka@gmail.com>2018-04-06 10:36:31 -0400
committerSamy Lanka <samy.lanka@gmail.com>2018-04-12 11:08:54 -0400
commitc05611bac298e6b904030e5e2e6efb79c4192a00 (patch)
tree89b6f508939b3a14ec36b34f39083cfa0faa3bcb /jstests/libs
parent364b712118561bf8483945e8614ba073e64669e3 (diff)
downloadmongo-c05611bac298e6b904030e5e2e6efb79c4192a00.tar.gz
SERVER-33287 Create passthrough that kills the primary node
Diffstat (limited to 'jstests/libs')
-rw-r--r--jstests/libs/override_methods/fail_unclean_shutdown_incompatible_commands.js49
-rw-r--r--jstests/libs/override_methods/fail_unclean_shutdown_start_parallel_shell.js12
2 files changed, 61 insertions, 0 deletions
diff --git a/jstests/libs/override_methods/fail_unclean_shutdown_incompatible_commands.js b/jstests/libs/override_methods/fail_unclean_shutdown_incompatible_commands.js
new file mode 100644
index 00000000000..2feca955c3d
--- /dev/null
+++ b/jstests/libs/override_methods/fail_unclean_shutdown_incompatible_commands.js
@@ -0,0 +1,49 @@
+/**
+ * This override prevents running commands that use the WiredTiger size storer. Because the size
+ * storer is only updated periodically, commands that use it after an unclean shutdown could return
+ * inaccurate results.
+ */
+(function() {
+ "use strict";
+
+ load("jstests/libs/override_methods/override_helpers.js");
+
+ function runCommandFailUncleanShutdownIncompatibleCommands(
+ conn, dbName, commandName, commandObj, func, makeFuncArgs) {
+ if (typeof commandObj !== "object" || commandObj === null) {
+ return func.apply(conn, makeFuncArgs(commandObj));
+ }
+
+ // If the command is in a wrapped form, then we look for the actual command object inside
+ // the query/$query object.
+ let commandObjUnwrapped = commandObj;
+ if (commandName === "query" || commandName === "$query") {
+ commandObjUnwrapped = commandObj[commandName];
+ commandName = Object.keys(commandObjUnwrapped)[0];
+ }
+
+ if (commandName === "count" && (!commandObjUnwrapped.hasOwnProperty("query") ||
+ Object.keys(commandObjUnwrapped["query"]).length === 0)) {
+ throw new Error("Cowardly fail if fastcount is run with a mongod that had an unclean" +
+ " shutdown: " + tojson(commandObjUnwrapped));
+ }
+
+ if (commandName === "dataSize" && !commandObjUnwrapped.hasOwnProperty("min") &&
+ !commandObjUnwrapped.hasOwnProperty("max")) {
+ throw new Error("Cowardly fail if unbounded dataSize is run with a mongod that had an" +
+ " unclean shutdown: " + tojson(commandObjUnwrapped));
+ }
+
+ if (commandName === "collStats" || commandName === "dbStats") {
+ throw new Error("Cowardly fail if " + commandName + " is run with a mongod that had" +
+ " an unclean shutdown: " + tojson(commandObjUnwrapped));
+ }
+
+ return func.apply(conn, makeFuncArgs(commandObj));
+ }
+
+ OverrideHelpers.prependOverrideInParallelShell(
+ "jstests/libs/override_methods/fail_unclean_shutdown_incompatible_commands.js");
+
+ OverrideHelpers.overrideRunCommand(runCommandFailUncleanShutdownIncompatibleCommands);
+})();
diff --git a/jstests/libs/override_methods/fail_unclean_shutdown_start_parallel_shell.js b/jstests/libs/override_methods/fail_unclean_shutdown_start_parallel_shell.js
new file mode 100644
index 00000000000..fabeff4915f
--- /dev/null
+++ b/jstests/libs/override_methods/fail_unclean_shutdown_start_parallel_shell.js
@@ -0,0 +1,12 @@
+/**
+ * This override cowardly fails if a parallel shell is started because the shell will exit after an
+ * unclean shutdown and won't be restarted when the node is restarted.
+ */
+(function() {
+ "use strict";
+
+ startParallelShell = function(jsCode, port, noConnect) {
+ throw new Error("Cowardly fail if startParallelShell is run with a mongod that had" +
+ " an unclean shutdown.");
+ };
+})();