summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/allow_disk_use_false_counter.js
blob: b73fc4ed75225f3a954617a7f79c68c561f44c05 (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
/**
 * Tests "metrics.query.allowDiskUseFalse" counter.
 */

(function() {
"use strict";

const mongod = MongoRunner.runMongod();
const db = mongod.getDB(jsTest.name());

const kAllowDiskUseFalse = "allowDiskUseFalse";

function getQueryMetrics() {
    return db.serverStatus().metrics.query;
}

function getAllowDiskUseFalseCounter() {
    return getQueryMetrics()[kAllowDiskUseFalse];
}

function runTest(cmdObject) {
    let allowDiskUseFalseValue = getAllowDiskUseFalseCounter();

    // Make sure that allowDiskUseFalse counter increments by 1 if a command with
    // {allowDiskUse:false} is called.
    assert.commandWorked(db.runCommand(Object.assign(cmdObject, {allowDiskUse: false})));
    allowDiskUseFalseValue += 1;
    assert.eq(allowDiskUseFalseValue, getAllowDiskUseFalseCounter());

    // Make sure that allowDiskUseFalse counter stays the same if a command with
    // {allowDiskUse:true} is called.
    assert.commandWorked(db.runCommand(Object.assign(cmdObject, {allowDiskUse: true})));
    assert.eq(allowDiskUseFalseValue, getAllowDiskUseFalseCounter());

    // Make sure that allowDiskUseFalse counter stays the same if a command without allowDiskUse
    // parameter is called.
    assert.commandWorked(db.runCommand(cmdObject));
    assert.eq(allowDiskUseFalseValue, getAllowDiskUseFalseCounter());

    // Make sure that allowDiskUseFalse counter increments by 1 if a command with
    // {allowDiskUse:false} is called a second time.
    assert.commandWorked(db.runCommand(Object.assign(cmdObject, {allowDiskUse: false})));
    allowDiskUseFalseValue += 1;
    assert.eq(allowDiskUseFalseValue, getAllowDiskUseFalseCounter());
}

// Check if the metrics.query.allowDiskUseFalse exists and by default equals to 0.
assert(getQueryMetrics().hasOwnProperty(kAllowDiskUseFalse));
assert.eq(0, getAllowDiskUseFalseCounter());

// Test on a collection.
const simpleCollName = "simple_coll";
const simpleColl = db[simpleCollName];
simpleColl.drop();
runTest({aggregate: simpleColl.getName(), pipeline: [], cursor: {}});
runTest({find: simpleColl.getName()});

// Test on a view.
const simpleViewName = "simple_view";
const simpleView = db[simpleViewName];
simpleView.drop();
assert.commandWorked(db.createView(simpleViewName, simpleCollName, [{$match: {a: 1}}]));
runTest({aggregate: simpleView.getName(), pipeline: [], cursor: {}});
runTest({find: simpleView.getName()});

MongoRunner.stopMongod(mongod);
})();