summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/concurrency/fsm_workloads/findAndModify_update_queue.js')
-rw-r--r--jstests/concurrency/fsm_workloads/findAndModify_update_queue.js104
1 files changed, 58 insertions, 46 deletions
diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js b/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js
index 0ca53015b68..8ed1a148afa 100644
--- a/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js
+++ b/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js
@@ -11,64 +11,76 @@
* This workload was designed to reproduce an issue similar to SERVER-18304 for update operations
* using the findAndModify command where the old version of the document is returned.
*/
-load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
-load('jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js'); // for $config
+load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
+load('jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js'); // for $config
load('jstests/concurrency/fsm_workload_helpers/server_types.js'); // for isMongod and isMMAPv1
-var $config = extendWorkload($config, function($config, $super) {
+var $config = extendWorkload(
+ $config,
+ function($config, $super) {
- // Use the workload name as the database name, since the workload name is assumed to be unique.
- $config.data.uniqueDBName = 'findAndModify_update_queue';
+ // Use the workload name as the database name, since the workload name is assumed to be
+ // unique.
+ $config.data.uniqueDBName = 'findAndModify_update_queue';
- $config.data.newDocForInsert = function newDocForInsert(i) {
- return { _id: i, rand: Random.rand(), counter: 0 };
- };
+ $config.data.newDocForInsert = function newDocForInsert(i) {
+ return {
+ _id: i,
+ rand: Random.rand(),
+ counter: 0
+ };
+ };
- $config.data.getIndexSpec = function getIndexSpec() {
- return { counter: 1, rand: -1 };
- };
+ $config.data.getIndexSpec = function getIndexSpec() {
+ return {
+ counter: 1,
+ rand: -1
+ };
+ };
- $config.data.opName = 'updated';
+ $config.data.opName = 'updated';
- var states = (function() {
+ var states = (function() {
- function update(db, collName) {
- // Update the counter field to avoid matching the same document again.
- var res = db.runCommand({
- findAndModify: db[collName].getName(),
- query: { counter: 0 },
- sort: { rand: -1 },
- update: { $inc: { counter: 1 } },
- new: false
- });
- assertAlways.commandWorked(res);
+ function update(db, collName) {
+ // Update the counter field to avoid matching the same document again.
+ var res = db.runCommand({
+ findAndModify: db[collName].getName(),
+ query: {counter: 0},
+ sort: {rand: -1},
+ update: {$inc: {counter: 1}}, new: false
+ });
+ assertAlways.commandWorked(res);
- var doc = res.value;
- if (isMongod(db) && !isMMAPv1(db)) {
- // MMAPv1 does not automatically retry if there was a conflict, so it is expected
- // that it may return null in the case of a conflict. All other storage engines
- // should automatically retry the operation, and thus should never return null.
- assertWhenOwnColl.neq(
- doc, null, 'findAndModify should have found and updated a matching document');
- }
- if (doc !== null) {
- this.saveDocId(db, collName, doc._id);
+ var doc = res.value;
+ if (isMongod(db) && !isMMAPv1(db)) {
+ // MMAPv1 does not automatically retry if there was a conflict, so it is
+ // expected
+ // that it may return null in the case of a conflict. All other storage engines
+ // should automatically retry the operation, and thus should never return null.
+ assertWhenOwnColl.neq(
+ doc,
+ null,
+ 'findAndModify should have found and updated a matching document');
+ }
+ if (doc !== null) {
+ this.saveDocId(db, collName, doc._id);
+ }
}
- }
- return {
- update: update
- };
+ return {
+ update: update
+ };
- })();
+ })();
- var transitions = {
- update: { update: 1 }
- };
+ var transitions = {
+ update: {update: 1}
+ };
- $config.startState = 'update';
- $config.states = states;
- $config.transitions = transitions;
+ $config.startState = 'update';
+ $config.states = states;
+ $config.transitions = transitions;
- return $config;
-});
+ return $config;
+ });