summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/benchrun_substitution.js
blob: 8d8eee3cc09f68e950a8b6bd78036943a63347b6 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function benchrun_sub_insert(use_write_command) {
    t = db.benchrun_sub;
    t.drop();
    var offset = 10000;
    ops = [{
        op: "insert",
        ns: "test.benchrun_sub",
        doc: {
            x: {"#RAND_INT": [0, 100]},
            curDate: {"#CUR_DATE": 0},
            futureDate: {"#CUR_DATE": offset},
            pastDate: {"#CUR_DATE": (0 - offset)}
        },
        writeCmd: use_write_command,
    }];

    res = benchRun({parallel: 1, seconds: 10, ops: ops, host: db.getMongo().host});

    assert.gt(res.insert, 0);

    t.find().forEach(function(doc) {
        var field = doc.x;
        assert.gte(field, 0);
        assert.lt(field, 100);
        assert.lt(doc.pastDate, doc.curDate);
        assert.lt(doc.curDate, doc.futureDate);
    });
}

function benchrun_sub_update(use_write_command) {
    t = db.benchrun_sub;
    t.drop();

    ops = [{
        op: "update",
        ns: "test.benchrun_sub",
        query: {x: {"#RAND_INT": [0, 100]}},
        update: {$inc: {x: 1}},
        writeCmd: use_write_command
    }];

    for (var i = 0; i < 100; ++i) {
        assert.commandWorked(t.insert({x: i}));
    }

    res = benchRun({parallel: 1, seconds: 10, ops: ops, host: db.getMongo().host});

    var field_sum = 0;
    t.find().forEach(function(doc) {
        field_sum += doc.x;
    });

    assert.gt(field_sum, 4950);  // 1 + 2 + .. 99 = 4950
}

function benchrun_sub_remove(use_write_command) {
    t = db.benchrun_sub;
    t.drop();

    ops = [{
        op: "remove",
        ns: "test.benchrun_sub",
        query: {x: {"#RAND_INT": [0, 100]}},
        writeCmd: use_write_command,
    }];

    for (var i = 0; i < 100; ++i) {
        assert.commandWorked(t.insert({x: i}));
    }

    res = benchRun({parallel: 1, seconds: 10, ops: ops, host: db.getMongo().host});

    assert.lt(t.count(), 100);
}

benchrun_sub_insert(true);
benchrun_sub_insert(false);
benchrun_sub_update(true);
benchrun_sub_update(false);
benchrun_sub_remove(true);
benchrun_sub_remove(false);