summaryrefslogtreecommitdiff
path: root/jstests/core/opcounters_active.js
blob: cf093103f473bbe264d5ba6ea2af67ad2afda0c8 (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
// checks that db.serverStatus will not throw errors when metrics tree is not present

(function() {
    "use strict";
    //Test the getActiveCommands function
    //Should remove the listCollections section but keep the rest
    var testInput = {
        "isMaster" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(3)
        },
        "mapreduce" : {
            "shardedfinish" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            }
        },
        "listCollections" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(0)
        }
    };
    var testExpected = {
        "isMaster" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(3)
        },
        "mapreduce" : {
            "shardedfinish" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            }
        }
    };
    var testResult = getActiveCommands(testInput);

    assert.eq(testResult, testExpected, "getActiveCommands did not return the expected result");

    //Test that the serverstatus helper works
    var result = db.serverStatus();
    assert.neq(undefined, result, result)
    //Test that the metrics tree returns
    assert.neq(undefined, result.metrics, result)
    //Test that the metrics.commands tree returns
    assert.neq(undefined, result.metrics.commands, result)
    //Test that the metrics.commands.serverStatus value is non-zero
    assert.neq(0, result.metrics.commands.serverStatus.total, result)

    //Test that the command returns successfully when no metrics tree is present
    var result = db.serverStatus({"metrics":0})
    assert.eq(undefined, result.metrics, result)
}());