diff options
Diffstat (limited to 'jstests/concurrency/fsm_libs')
-rw-r--r-- | jstests/concurrency/fsm_libs/cluster.js | 11 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/composer.js | 15 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/fsm.js | 11 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/parse_config.js | 60 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/runner.js | 28 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/thread_mgr.js | 20 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/worker_thread.js | 37 |
7 files changed, 75 insertions, 107 deletions
diff --git a/jstests/concurrency/fsm_libs/cluster.js b/jstests/concurrency/fsm_libs/cluster.js index 5a350c9836d..a587d8f323a 100644 --- a/jstests/concurrency/fsm_libs/cluster.js +++ b/jstests/concurrency/fsm_libs/cluster.js @@ -97,10 +97,7 @@ var Cluster = function(options) { var initialized = false; var clusterStartTime; - var _conns = { - mongos: [], - mongod: [] - }; + var _conns = {mongos: [], mongod: []}; var nextConn = 0; var replSets = []; @@ -342,11 +339,7 @@ var Cluster = function(options) { return ''; } - var cluster = { - mongos: [], - config: [], - shards: {} - }; + var cluster = {mongos: [], config: [], shards: {}}; var i = 0; var mongos = st.s0; diff --git a/jstests/concurrency/fsm_libs/composer.js b/jstests/concurrency/fsm_libs/composer.js index 495648fb01a..99cfb64f34d 100644 --- a/jstests/concurrency/fsm_libs/composer.js +++ b/jstests/concurrency/fsm_libs/composer.js @@ -51,12 +51,11 @@ var composer = (function() { } var args = configs[workload]; - Object.keys(args.states) - .forEach(function(state) { - if (state !== args.startState) { - otherStates.push({workload: workload, state: state}); - } - }); + Object.keys(args.states).forEach(function(state) { + if (state !== args.startState) { + otherStates.push({workload: workload, state: state}); + } + }); }); var next = getRandomElem(otherStates, Random.rand()); @@ -70,8 +69,6 @@ var composer = (function() { return items[Math.floor(randVal * items.length)]; } - return { - run: runCombinedFSM - }; + return {run: runCombinedFSM}; })(); diff --git a/jstests/concurrency/fsm_libs/fsm.js b/jstests/concurrency/fsm_libs/fsm.js index 0a3e4a45bf4..e7a3eafb946 100644 --- a/jstests/concurrency/fsm_libs/fsm.js +++ b/jstests/concurrency/fsm_libs/fsm.js @@ -21,11 +21,7 @@ var fsm = (function() { // See fsm_libs/cluster.js for the format of args.cluster. var connCache; if (args.passConnectionCache) { - connCache = { - mongos: [], - config: [], - shards: {} - }; + connCache = {mongos: [], config: [], shards: {}}; connCache.mongos = args.cluster.mongos.map(connStr => new Mongo(connStr)); connCache.config = args.cluster.config.map(connStr => new Mongo(connStr)); @@ -87,8 +83,5 @@ var fsm = (function() { assert(false, 'not reached'); } - return { - run: runFSM, - _getWeightedRandomChoice: getWeightedRandomChoice - }; + return {run: runFSM, _getWeightedRandomChoice: getWeightedRandomChoice}; })(); diff --git a/jstests/concurrency/fsm_libs/parse_config.js b/jstests/concurrency/fsm_libs/parse_config.js index b569f660c8a..3c365dc5f4c 100644 --- a/jstests/concurrency/fsm_libs/parse_config.js +++ b/jstests/concurrency/fsm_libs/parse_config.js @@ -36,44 +36,40 @@ function parseConfig(config) { assert.eq('object', typeof config.states); assert.gt(Object.keys(config.states).length, 0); - Object.keys(config.states) - .forEach(function(k) { - assert.eq( - 'function', typeof config.states[k], 'config.states.' + k + ' is not a function'); - if (config.passConnectionCache) { - assert.eq(3, - config.states[k].length, - 'if passConnectionCache is true, state functions should ' + - 'accept 3 parameters: db, collName, and connCache'); - } else { - assert.eq(2, - config.states[k].length, - 'if passConnectionCache is false, state functions should ' + - 'accept 2 parameters: db and collName'); - } - }); + Object.keys(config.states).forEach(function(k) { + assert.eq('function', typeof config.states[k], 'config.states.' + k + ' is not a function'); + if (config.passConnectionCache) { + assert.eq(3, + config.states[k].length, + 'if passConnectionCache is true, state functions should ' + + 'accept 3 parameters: db, collName, and connCache'); + } else { + assert.eq(2, + config.states[k].length, + 'if passConnectionCache is false, state functions should ' + + 'accept 2 parameters: db and collName'); + } + }); // assert all states mentioned in config.transitions are present in config.states assert.eq('object', typeof config.transitions); assert.gt(Object.keys(config.transitions).length, 0); - Object.keys(config.transitions) - .forEach(function(fromState) { - assert(config.states.hasOwnProperty(fromState), - 'config.transitions contains a state not in config.states: ' + fromState); + Object.keys(config.transitions).forEach(function(fromState) { + assert(config.states.hasOwnProperty(fromState), + 'config.transitions contains a state not in config.states: ' + fromState); - assert.gt(Object.keys(config.transitions[fromState]).length, 0); - Object.keys(config.transitions[fromState]) - .forEach(function(toState) { - assert(config.states.hasOwnProperty(toState), - 'config.transitions.' + fromState + - ' contains a state not in config.states: ' + toState); - assert.eq('number', - typeof config.transitions[fromState][toState], - 'transitions.' + fromState + '.' + toState + ' should be a number'); - assert(!isNaN(config.transitions[fromState][toState]), - 'transitions.' + fromState + '.' + toState + ' cannot be NaN'); - }); + assert.gt(Object.keys(config.transitions[fromState]).length, 0); + Object.keys(config.transitions[fromState]).forEach(function(toState) { + assert(config.states.hasOwnProperty(toState), + 'config.transitions.' + fromState + ' contains a state not in config.states: ' + + toState); + assert.eq('number', + typeof config.transitions[fromState][toState], + 'transitions.' + fromState + '.' + toState + ' should be a number'); + assert(!isNaN(config.transitions[fromState][toState]), + 'transitions.' + fromState + '.' + toState + ' cannot be NaN'); }); + }); config.setup = config.setup || function() {}; assert.eq('function', typeof config.setup); diff --git a/jstests/concurrency/fsm_libs/runner.js b/jstests/concurrency/fsm_libs/runner.js index 4881676636d..cba8c4efe8a 100644 --- a/jstests/concurrency/fsm_libs/runner.js +++ b/jstests/concurrency/fsm_libs/runner.js @@ -214,9 +214,7 @@ var runner = (function() { myDB[collName].drop(); if (cluster.isSharded()) { - var shardKey = context[workload].config.data.shardKey || { - _id: 'hashed' - }; + var shardKey = context[workload].config.data.shardKey || {_id: 'hashed'}; // TODO: allow workload config data to specify split cluster.shardCollection(myDB[collName], shardKey, false); } @@ -328,11 +326,13 @@ var runner = (function() { numUniqueTraces + ' of which were unique:\n\n'; return summary + - uniqueTraces.map(function(obj) { - var line = pluralize('thread', obj.freq) + ' with tids ' + - JSON.stringify(obj.tids) + ' threw\n'; - return indent(line + obj.value, 8); - }).join('\n\n'); + uniqueTraces + .map(function(obj) { + var line = pluralize('thread', obj.freq) + ' with tids ' + + JSON.stringify(obj.tids) + ' threw\n'; + return indent(line + obj.value, 8); + }) + .join('\n\n'); } if (workerErrs.length > 0) { @@ -401,9 +401,7 @@ var runner = (function() { workloads.forEach(function(workload) { load(workload); // for $config assert.neq('undefined', typeof $config, '$config was not defined by ' + workload); - context[workload] = { - config: parseConfig($config) - }; + context[workload] = {config: parseConfig($config)}; if (applyMultipliers) { context[workload].config.iterations *= executionOptions.iterationMultiplier; context[workload].config.threadCount *= executionOptions.threadMultiplier; @@ -525,7 +523,7 @@ var runner = (function() { } finally { // Threads must be joined before destruction, so do this // even in the presence of exceptions. - errors.push(... threadMgr.joinAll().map( + errors.push(...threadMgr.joinAll().map( e => new WorkloadFailure( e.err, e.stack, e.tid, 'Foreground ' + e.workloads.join(' ')))); } @@ -630,8 +628,8 @@ var runner = (function() { var dbHashBlacklist = ['local']; if (cleanupOptions.dropDatabaseBlacklist) { - dbBlacklist.push(... cleanupOptions.dropDatabaseBlacklist); - dbHashBlacklist.push(... cleanupOptions.dropDatabaseBlacklist); + dbBlacklist.push(...cleanupOptions.dropDatabaseBlacklist); + dbHashBlacklist.push(...cleanupOptions.dropDatabaseBlacklist); } if (!cleanupOptions.keepExistingDatabases) { dropAllDatabases(cluster.getDB('test'), dbBlacklist); @@ -703,7 +701,7 @@ var runner = (function() { } finally { // Set a flag so background threads know to terminate. bgThreadMgr.markAllForTermination(); - errors.push(... bgThreadMgr.joinAll().map( + errors.push(...bgThreadMgr.joinAll().map( e => new WorkloadFailure( e.err, e.stack, e.tid, 'Background ' + e.workloads.join(' ')))); } diff --git a/jstests/concurrency/fsm_libs/thread_mgr.js b/jstests/concurrency/fsm_libs/thread_mgr.js index 145fb57146e..9680e22435b 100644 --- a/jstests/concurrency/fsm_libs/thread_mgr.js +++ b/jstests/concurrency/fsm_libs/thread_mgr.js @@ -211,22 +211,18 @@ workerThread.fsm = function(workloads, args, options) { load('jstests/concurrency/fsm_libs/worker_thread.js'); // for workerThread.main load('jstests/concurrency/fsm_libs/fsm.js'); // for fsm.run - return workerThread.main(workloads, - args, - function(configs) { - var workloads = Object.keys(configs); - assert.eq(1, workloads.length); - fsm.run(configs[workloads[0]]); - }); + return workerThread.main(workloads, args, function(configs) { + var workloads = Object.keys(configs); + assert.eq(1, workloads.length); + fsm.run(configs[workloads[0]]); + }); }; workerThread.composed = function(workloads, args, options) { load('jstests/concurrency/fsm_libs/worker_thread.js'); // for workerThread.main load('jstests/concurrency/fsm_libs/composer.js'); // for composer.run - return workerThread.main(workloads, - args, - function(configs) { - composer.run(workloads, configs, options); - }); + return workerThread.main(workloads, args, function(configs) { + composer.run(workloads, configs, options); + }); }; diff --git a/jstests/concurrency/fsm_libs/worker_thread.js b/jstests/concurrency/fsm_libs/worker_thread.js index 5c6dd771509..7a9bf6b3304 100644 --- a/jstests/concurrency/fsm_libs/worker_thread.js +++ b/jstests/concurrency/fsm_libs/worker_thread.js @@ -62,21 +62,20 @@ var workerThread = (function() { // configurable, enumerable, and writable. To prevent workloads from changing // the iterations and threadCount properties in their state functions, we redefine // them here as non-configurable, non-enumerable, and non-writable. - Object.defineProperties(data, - { - 'iterations': { - configurable: false, - enumerable: false, - writable: false, - value: data.iterations - }, - 'threadCount': { - configurable: false, - enumerable: false, - writable: false, - value: data.threadCount - } - }); + Object.defineProperties(data, { + 'iterations': { + configurable: false, + enumerable: false, + writable: false, + value: data.iterations + }, + 'threadCount': { + configurable: false, + enumerable: false, + writable: false, + value: data.threadCount + } + }); data.tid = args.tid; configs[workload] = { @@ -103,9 +102,7 @@ var workerThread = (function() { Random.setRandomSeed(args.seed); run(configs); - return { - ok: 1 - }; + return {ok: 1}; } catch (e) { args.errorLatch.countDown(); return { @@ -124,8 +121,6 @@ var workerThread = (function() { } } - return { - main: main - }; + return {main: main}; })(); |