From d5b1d3a1eb23e3249c3dee05c29c010c7693fbaf Mon Sep 17 00:00:00 2001 From: Huayu Ouyang Date: Wed, 23 Sep 2020 21:39:11 +0000 Subject: SERVER-50419 Test that serverStatus metrics correctly print commands.hello if the user sends hello --- .../server_status_metrics_hello_command.js | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 jstests/noPassthrough/server_status_metrics_hello_command.js diff --git a/jstests/noPassthrough/server_status_metrics_hello_command.js b/jstests/noPassthrough/server_status_metrics_hello_command.js new file mode 100644 index 00000000000..8aacfedae2f --- /dev/null +++ b/jstests/noPassthrough/server_status_metrics_hello_command.js @@ -0,0 +1,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); +})(); -- cgit v1.2.1