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

/**
 * explain_remove.js
 *
 * Runs explain() and remove() on a collection.
 */
load('jstests/concurrency/fsm_libs/extend_workload.js');  // for extendWorkload
load('jstests/concurrency/fsm_workloads/explain.js');     // for $config

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

        $config.states = Object.extend(
            {
              explainSingleRemove: function explainSingleRemove(db, collName) {
                  var res = db[collName]
                                .explain('executionStats')
                                .remove({i: this.nInserted}, /* justOne */ true);
                  assertAlways.commandWorked(res);
                  assertWhenOwnColl(function() {
                      assertWhenOwnColl.eq(1, res.executionStats.totalDocsExamined);

                      // the document should not have been deleted.
                      assertWhenOwnColl.eq(1, db[collName].find({i: this.nInserted}).itcount());
                  }.bind(this));
              },
              explainMultiRemove: function explainMultiRemove(db, collName) {
                  var res = db[collName]
                                .explain('executionStats')
                                .remove({i: {$lte: this.nInserted / 2}});
                  assertAlways.commandWorked(res);
                  assertWhenOwnColl(function() {
                      assertWhenOwnColl.eq(this.nInserted / 2 + 1,
                                           explain.executionStats.totalDocsExamined);
                      // no documents should have been deleted
                      assertWhenOwnColl.eq(this.nInserted, db[collName].itcount());
                  }.bind(this));
              }
            },
            $super.states);

        $config.transitions =
            Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)},
                          $super.transitions);

        return $config;
    });