summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/indexed_insert_eval.js
blob: a7a4797efefb3f6e1deafa7d517da5d4729da095 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';

/**
 * indexed_insert_eval.js
 *
 * Inserts multiple documents into an indexed collection using the eval command.
 * Asserts that all documents appear in both a collection scan and an index
 * scan. The indexed value is the thread id.
 */
load('jstests/concurrency/fsm_libs/extend_workload.js');  // for extendWorkload
load('jstests/concurrency/fsm_workloads/indexed_insert_base.js');  // for $config

var $config =
    extendWorkload($config,
                   function($config, $super) {

                       $config.data.nolock = false;

                       $config.states.insert = function insert(db, collName) {
                           var evalResult = db.runCommand({
                               eval: function(collName, doc) {
                                   var insertResult = db[collName].insert(doc);
                                   return tojson(insertResult);
                               },
                               args: [collName, this.getDoc()],
                               nolock: this.nolock
                           });
                           assertAlways.commandWorked(evalResult);
                           var insertResult = JSON.parse(evalResult.retval);
                           assertAlways.eq(1, insertResult.nInserted, tojson(insertResult));
                           this.nInserted += this.docsPerInsert;
                       };

                       return $config;
                   });