summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/awaitable_hello.js
diff options
context:
space:
mode:
authorMoustafa Maher <m.maher@10gen.com>2021-01-29 21:33:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-05 21:18:38 +0000
commit48378a8ef6f2eec3f7aff4fe7c0bdad6a44b639c (patch)
tree256d4f99f7327298f8542a648cb58fe26dd521a9 /jstests/noPassthrough/awaitable_hello.js
parent857ec7949839102d30b1bf3c82b1437a70970084 (diff)
downloadmongo-48378a8ef6f2eec3f7aff4fe7c0bdad6a44b639c.tar.gz
SERVER-54120 Move away from getLog to check if a command is done in our tests
Diffstat (limited to 'jstests/noPassthrough/awaitable_hello.js')
-rw-r--r--jstests/noPassthrough/awaitable_hello.js42
1 files changed, 22 insertions, 20 deletions
diff --git a/jstests/noPassthrough/awaitable_hello.js b/jstests/noPassthrough/awaitable_hello.js
index e3f255e5b98..871396ffc21 100644
--- a/jstests/noPassthrough/awaitable_hello.js
+++ b/jstests/noPassthrough/awaitable_hello.js
@@ -9,7 +9,7 @@ load("jstests/libs/fail_point_util.js");
load("jstests/libs/parallel_shell_helpers.js");
// runTest takes in the hello command or its aliases, isMaster and ismaster.
-function runTest(db, cmd) {
+function runTest(db, cmd, logFailpoint) {
// Check the command response contains a topologyVersion even if maxAwaitTimeMS and
// topologyVersion are not included in the request.
const res = assert.commandWorked(db.runCommand(cmd));
@@ -34,6 +34,11 @@ function runTest(db, cmd) {
assert.commandWorked(db.adminCommand({clearLog: 'global'}));
let now = new Date();
jsTestLog(`Running slow ${cmd}`);
+
+ // Get the slow query log failpoint for the command, to know the current timesEntered before
+ // the command runs.
+ const timesEnteredBeforeRunningCommand = configureFailPoint(db, logFailpoint).timesEntered;
+
assert.commandWorked(
db.runCommand({[cmd]: 1, topologyVersion: topologyVersionField, maxAwaitTimeMS: 20000}));
let commandDuration = new Date() - now;
@@ -43,11 +48,10 @@ function runTest(db, cmd) {
10000,
cmd + ` command should have taken at least 10000ms, but completed in ${commandDuration}ms`);
- assert(!checkLog.checkContainsOnceJson(db.getMongo(), 51803, {
- 'command': function(obj) {
- return obj.hasOwnProperty(cmd);
- }
- }));
+ // Get the slow query log failpoint for the command, to make sure that it didn't get hit during
+ // the command run by checking that timesEntered is the same as before.
+ const timesEnteredAfterRunningCommand = configureFailPoint(db, logFailpoint).timesEntered;
+ assert(timesEnteredBeforeRunningCommand == timesEnteredAfterRunningCommand);
// Check that the command appears in the slow query log if it's unexpectedly slow.
function runHelloCommand(cmd, topologyVersionField) {
@@ -65,13 +69,11 @@ function runTest(db, cmd) {
helloFailpoint.wait();
sleep(1000); // Make the command hang for a second in the parallel shell.
helloFailpoint.off();
+ const logFailPoint = configureFailPoint(db, logFailpoint);
awaitHello();
- checkLog.containsJson(db.getMongo(), 51803, {
- 'command': function(obj) {
- return obj.hasOwnProperty(cmd);
- }
- });
+ // Wait for the command to be logged.
+ logFailPoint.wait();
// Check that when a different processId is given, the server responds immediately.
now = new Date();
@@ -204,18 +206,18 @@ function runTest(db, cmd) {
// Set command log verbosity to 0 to avoid logging *all* commands in the "slow query" log.
const conn = MongoRunner.runMongod({setParameter: {logComponentVerbosity: tojson({command: 0})}});
assert.neq(null, conn, "mongod was unable to start up");
-runTest(conn.getDB("admin"), "hello");
-runTest(conn.getDB("admin"), "isMaster");
-runTest(conn.getDB("admin"), "ismaster");
+runTest(conn.getDB("admin"), "hello", "waitForHelloCommandLogged");
+runTest(conn.getDB("admin"), "isMaster", "waitForIsMasterCommandLogged");
+runTest(conn.getDB("admin"), "ismaster", "waitForIsMasterCommandLogged");
MongoRunner.stopMongod(conn);
const replTest = new ReplSetTest(
{nodes: 1, nodeOptions: {setParameter: {logComponentVerbosity: tojson({command: 0})}}});
replTest.startSet();
replTest.initiate();
-runTest(replTest.getPrimary().getDB("admin"), "hello");
-runTest(replTest.getPrimary().getDB("admin"), "isMaster");
-runTest(replTest.getPrimary().getDB("admin"), "ismaster");
+runTest(replTest.getPrimary().getDB("admin"), "hello", "waitForHelloCommandLogged");
+runTest(replTest.getPrimary().getDB("admin"), "isMaster", "waitForIsMasterCommandLogged");
+runTest(replTest.getPrimary().getDB("admin"), "ismaster", "waitForIsMasterCommandLogged");
replTest.stopSet();
const st = new ShardingTest({
@@ -224,8 +226,8 @@ const st = new ShardingTest({
config: 1,
other: {mongosOptions: {setParameter: {logComponentVerbosity: tojson({command: 0})}}}
});
-runTest(st.s.getDB("admin"), "hello");
-runTest(st.s.getDB("admin"), "isMaster");
-runTest(st.s.getDB("admin"), "ismaster");
+runTest(st.s.getDB("admin"), "hello", "waitForHelloCommandLogged");
+runTest(st.s.getDB("admin"), "isMaster", "waitForIsMasterCommandLogged");
+runTest(st.s.getDB("admin"), "ismaster", "waitForIsMasterCommandLogged");
st.stop();
})();