summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/findAndModify_remove.js
blob: 3c20a7ae61f1b3958baee33e9c98752e8b8103ec (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
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';

/**
 * findAndModify_remove.js
 *
 * Each thread repeatedly inserts a document, and subsequently performs
 * the findAndModify command to remove it.
 */
var $config = (function() {
    var data = {shardKey: {tid: 1}};

    var states = (function() {
        function init(db, collName) {
            this.iter = 0;
        }

        function insertAndRemove(db, collName) {
            var res = db[collName].insert({tid: this.tid, value: this.iter});
            assertAlways.commandWorked(res);
            assertAlways.eq(1, res.nInserted);

            res = db.runCommand({
                findandmodify: db[collName].getName(),
                query: {tid: this.tid},
                sort: {iter: -1},
                remove: true
            });
            assertAlways.commandWorked(res);

            var doc = res.value;
            assertWhenOwnColl(doc !== null, 'query spec should have matched a document');

            if (doc !== null) {
                assertAlways.eq(this.tid, doc.tid);
                assertWhenOwnColl.eq(this.iter, doc.value);
            }

            this.iter++;
        }

        return {init: init, insertAndRemove: insertAndRemove};
    })();

    var transitions = {init: {insertAndRemove: 1}, insertAndRemove: {insertAndRemove: 1}};

    return {threadCount: 20, iterations: 20, data: data, states: states, transitions: transitions};
})();