summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/update_upsert.js
blob: f0b4da763eafbdfe72da6f72fd27e5da2985902b (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
'use strict';

/**
 * update_upsert_multi.js
 *
 * Tests updates that specify upsert=true.
 */

var $config = (function() {
    let states = {
        update: function update(db, collName) {
            const docId = Random.randInt(5) * 4;
            let updateRes =
                assert.writeOK(db[collName].update({_id: docId}, {$inc: {x: 1}}, {upsert: true}));
            assertAlways.eq(1,
                            updateRes.nMatched + updateRes.nUpserted,
                            "unexpected matched count: " + updateRes);
            assertAlways.eq(1,
                            updateRes.nModified + updateRes.nUpserted,
                            "unexpected modified count: " + updateRes);
        },
    };

    let transitions = {
        update: {update: 1},
    };

    function teardown(db, collName, cluster) {
        assertAlways.eq(0, db[collName].countDocuments({_id: {$nin: [0, 4, 8, 12, 16]}}));
        assertAlways.lt(0, db[collName].countDocuments({_id: {$in: [0, 4, 8, 12, 16]}}));
    }

    return {
        threadCount: 10,
        iterations: 20,
        states: states,
        startState: 'update',
        transitions: transitions,
        teardown: teardown,
    };
})();