diff options
Diffstat (limited to 'jstests/libs')
-rw-r--r-- | jstests/libs/parallelTester.js | 37 | ||||
-rw-r--r-- | jstests/libs/test_background_ops.js | 3 |
2 files changed, 37 insertions, 3 deletions
diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js index bbe2d19ee6c..fc34cb668f8 100644 --- a/jstests/libs/parallelTester.js +++ b/jstests/libs/parallelTester.js @@ -2,13 +2,46 @@ * The ParallelTester class is used to test more than one test concurrently */ if (typeof _threadInject != "undefined") { + // With --enableJavaScriptProtection functions are presented as Code objects. + // This function evals all the Code objects then calls the provided start function. + // arguments: [startFunction, startFunction args...] + function _threadStartWrapper() { + // Recursively evals all the Code objects present in arguments + // NOTE: This is a naive implementation that cannot handle cyclic objects. + function evalCodeArgs(arg) { + if (arg instanceof Code) { + return eval("(" + arg.code + ")"); + } else if (arg !== null && isObject(arg)) { + var newArg = arg instanceof Array ? [] : {}; + for (var prop in arg) { + if (arg.hasOwnProperty(prop)) { + newArg[prop] = evalCodeArgs(arg[prop]); + } + } + return newArg; + } + return arg; + } + var realStartFn; + var newArgs = []; + for (var i = 0, l = arguments.length; i < l; i++) { + newArgs.push(evalCodeArgs(arguments[i])); + } + realStartFn = newArgs.shift(); + return realStartFn.apply(this, newArgs); + } + Thread = function() { - this.init.apply(this, arguments); + var args = Array.prototype.slice.call(arguments); + args.unshift(_threadStartWrapper); + this.init.apply(this, args); }; _threadInject(Thread.prototype); ScopedThread = function() { - this.init.apply(this, arguments); + var args = Array.prototype.slice.call(arguments); + args.unshift(_threadStartWrapper); + this.init.apply(this, args); }; ScopedThread.prototype = new Thread(function() {}); _scopedThreadInject(ScopedThread.prototype); diff --git a/jstests/libs/test_background_ops.js b/jstests/libs/test_background_ops.js index ce21a636ff6..384e0bd5b64 100644 --- a/jstests/libs/test_background_ops.js +++ b/jstests/libs/test_background_ops.js @@ -138,6 +138,7 @@ startParallelOps = function(mongo, proc, args, context) { var bootstrapper = function(stored) { var procContext = stored.procContext; + eval("procContext = " + procContext); procContext.setup(procContext, stored); var contexts = stored.contexts; @@ -177,7 +178,7 @@ startParallelOps = function(mongo, proc, args, context) { bootstrapper: tojson(bootstrapper), operation: tojson(proc), args: tojson(args), - procContext: procContext, + procContext: tojson(procContext), contexts: tojson(contexts) }); |