summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/sharding/sharding_test_options_immutable.js25
-rw-r--r--src/mongo/shell/replsettest.js6
-rw-r--r--src/mongo/shell/shardingtest.js3
3 files changed, 32 insertions, 2 deletions
diff --git a/jstests/sharding/sharding_test_options_immutable.js b/jstests/sharding/sharding_test_options_immutable.js
new file mode 100644
index 00000000000..fb904afe6ac
--- /dev/null
+++ b/jstests/sharding/sharding_test_options_immutable.js
@@ -0,0 +1,25 @@
+/*
+ * Ensure options object passed to ShardingTest is not mutated.
+ */
+
+(function() {
+'use strict';
+
+const opts = {
+ setParameter: {},
+};
+
+try {
+ const st = new ShardingTest({
+ mongos: [opts],
+ config: [opts],
+ rs: {nodes: [opts]},
+ shards: 1,
+ });
+ st.stop();
+} catch (e) {
+ assert(false, `ShardingTest threw an error: ${tojson(e)}`);
+} finally {
+ assert.eq(opts, {setParameter: {}});
+}
+})();
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index bd1f5a58ba5..a3a3e081b1e 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -3336,6 +3336,8 @@ var ReplSetTest = function(opts) {
self.nodeOptions = nodeOptions;
}
+ // If opts is passed in as a string, let it pass unmodified since strings are pass-by-value.
+ // if it is an object, though, pass in a deep copy.
if (typeof opts === 'string' || opts instanceof String) {
retryOnNetworkError(function() {
// The primary may unexpectedly step down during startup if under heavy load
@@ -3344,9 +3346,9 @@ var ReplSetTest = function(opts) {
_constructFromExistingSeedNode(opts);
}, ReplSetTest.kDefaultRetries);
} else if (typeof opts.rstArgs === "object") {
- _constructFromExistingNodes(opts.rstArgs);
+ _constructFromExistingNodes(Object.extend({}, opts.rstArgs, true));
} else {
- _constructStartNewInstances(opts);
+ _constructStartNewInstances(Object.extend({}, opts, true));
}
/**
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index b2f2d8ee70e..35cf6ecec4d 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -113,6 +113,9 @@ var ShardingTest = function(params) {
// concern (5 minutes)
var kDefaultWTimeoutMs = 5 * 60 * 1000;
+ // Ensure we don't mutate the passed-in parameters.
+ params = Object.extend({}, params, true);
+
// Publicly exposed variables
/**