summaryrefslogtreecommitdiff
path: root/jstests/core/opcounters_active.js
blob: 7df8c26b6c07672998736d2a4869ec1744011717 (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
// 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": {"failed": NumberLong(0), "total": NumberLong(1)},
    "listCollections": {"failed": NumberLong(0), "total": NumberLong(0)}
};
var testExpected = {
    "isMaster": {"failed": NumberLong(0), "total": NumberLong(3)},
    "mapreduce": {"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, tojson(result));
// Test that the metrics tree returns
assert.neq(undefined, result.metrics, tojson(result));
// Test that the metrics.commands tree returns
assert.neq(undefined, result.metrics.commands, tojson(result));
// Test that the metrics.commands.serverStatus value is non-zero
assert.neq(0, result.metrics.commands.serverStatus.total, tojson(result));

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