summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/touch_base.js
blob: df419e17db7fe15c6b8d2b83fb20ae511b1a183e (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';

/**
 * touch_base.js
 *
 * Bulk inserts documents in batches of 100, uses the touch command on "data" and "index",
 * and queries to verify the number of documents inserted by the thread.
 */

load('jstests/concurrency/fsm_libs/extend_workload.js');            // for extendWorkload
load('jstests/concurrency/fsm_workloads/indexed_insert_where.js');  // for $config
// For isMongod, isMMAPv1, and isEphemeral.
load('jstests/concurrency/fsm_workload_helpers/server_types.js');

var $config =
    extendWorkload($config,
                   function($config, $super) {
                       $config.data.generateDocumentToInsert = function generateDocumentToInsert() {
                           return {
                               tid: this.tid,
                               x: Random.randInt(10)
                           };
                       };

                       $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) {
                           return {
                               touch: collName,
                               data: true,
                               index: true
                           };
                       };

                       $config.states.touch = function touch(db, collName) {
                           var res = db.runCommand(this.generateTouchCmdObj(collName));
                           if (isMongod(db) && (isMMAPv1(db) || isEphemeral(db))) {
                               assertAlways.commandWorked(res);
                           } else {
                               // SERVER-16850 and SERVER-16797
                               assertAlways.commandFailed(res);
                           }
                       };

                       $config.states.query = function query(db, collName) {
                           var count = db[collName].find({tid: this.tid}).itcount();
                           assertWhenOwnColl.eq(
                               count,
                               this.insertedDocuments,
                               'collection scan should return the number of documents this thread' +
                                   ' inserted');
                       };

                       $config.transitions = {
                           insert: {insert: 0.2, touch: 0.4, query: 0.4},
                           touch: {insert: 0.4, touch: 0.2, query: 0.4},
                           query: {insert: 0.4, touch: 0.4, query: 0.2}
                       };

                       $config.setup = function setup(db, collName, cluster) {
                           assertAlways.commandWorked(db[collName].ensureIndex({x: 1}));
                       };

                       return $config;
                   });