summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/server_status_metrics_hello_command.js
blob: 8aacfedae2f06ca53e40326eab349c2fc43a3435 (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
/**
 * Tests that serverStatus metrics correctly print commands.hello if the user sends hello
 * and commands.isMaster if the user sends isMaster or ismaster
 */
(function() {
"use strict";
const mongod = MongoRunner.runMongod();
const dbName = "server_status_metrics_hello_command";
const db = mongod.getDB(dbName);
let serverStatusMetrics = db.serverStatus().metrics.commands;
const initialIsMasterTotal = serverStatusMetrics.isMaster.total;
const initialHelloTotal = 0;

// Running hello command.
jsTestLog("Running hello command");
assert.commandWorked(db.runCommand({hello: 1}));
serverStatusMetrics = db.serverStatus().metrics.commands;
assert.eq(
    serverStatusMetrics.hello.total, initialHelloTotal + 1, "commands.hello should increment");
assert.eq(serverStatusMetrics.isMaster.total,
          initialIsMasterTotal,
          "commands.isMaster should not increment");

// Running isMaster command.
jsTestLog("Running isMaster command");
assert.commandWorked(db.runCommand({isMaster: 1}));
serverStatusMetrics = db.serverStatus().metrics.commands;
assert.eq(
    serverStatusMetrics.hello.total, initialHelloTotal + 1, "commands.hello should not increment");
assert.eq(serverStatusMetrics.isMaster.total,
          initialIsMasterTotal + 1,
          "commands.isMaster should increment");

// Running ismaster command.
jsTestLog("Running ismaster command");
assert.commandWorked(db.runCommand({ismaster: 1}));
serverStatusMetrics = db.serverStatus().metrics.commands;
assert.eq(
    serverStatusMetrics.hello.total, initialHelloTotal + 1, "commands.hello should not increment");
assert.eq(serverStatusMetrics.isMaster.total,
          initialIsMasterTotal + 2,
          "commands.isMaster should increment");
MongoRunner.stopMongod(mongod);
})();