From c4ce50093e9fcd603a2311aaa47fc04d536bf44f Mon Sep 17 00:00:00 2001 From: Denis Grebennicov Date: Thu, 15 Dec 2022 13:03:32 +0100 Subject: SERVER-66337 Ensure that check for the interrupt is done on every getNext() call in datasize_kill_op.js --- jstests/noPassthrough/datasize_kill_op.js | 58 ++++++++++++++++++++++ .../noPassthroughWithMongod/datasize_kill_op.js | 41 --------------- 2 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 jstests/noPassthrough/datasize_kill_op.js delete mode 100644 jstests/noPassthroughWithMongod/datasize_kill_op.js diff --git a/jstests/noPassthrough/datasize_kill_op.js b/jstests/noPassthrough/datasize_kill_op.js new file mode 100644 index 00000000000..ad7b435ca2e --- /dev/null +++ b/jstests/noPassthrough/datasize_kill_op.js @@ -0,0 +1,58 @@ +// Test that the dataSize command can be interrupted. Failpoint is defined for mongod only, +// therefore this test is running only in unsharded setup. + +(function() { +"use strict"; + +load("jstests/libs/fail_point_util.js"); // For configureFailPoint. +load("jstests/libs/wait_for_command.js"); // For waitForCommand. +load("jstests/libs/parallel_shell_helpers.js"); // For funWithArgs. + +const mongodOptions = {}; +const conn = MongoRunner.runMongod(mongodOptions); +assert.neq(null, conn, `mongod failed to start with options ${tojson(mongodOptions)}`); + +const dbName = `${jsTest.name()}_db`; +const db = conn.getDB(dbName); +assert.commandWorked(db.dropDatabase()); +assert.commandWorked(db.createCollection("foo")); + +const coll = db.foo; +coll.drop(); +coll.insert({_id: 0, s: "asdasdasdasdasdasdasd"}); + +const dataSizeCommand = { + "dataSize": dbName + ".foo", + "keyPattern": {"_id": 1}, + "min": {"_id": 0}, + "max": {"_id": 1} +}; + +// Set the yield iterations to 1 such that on every getNext() call we check for yield or interrupt. +assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryExecYieldIterations: 1})); + +// Configure the failpoint. +const failpoint = configureFailPoint(db, "hangBeforeDatasizeCount"); + +// Launch a parallel shell that runs the dataSize command, that should fail due to interrupt. +const awaitShell = + startParallelShell(funWithArgs(function(cmd) { + assert.commandFailedWithCode(db.runCommand(cmd), ErrorCodes.Interrupted); + }, dataSizeCommand), db.getMongo().port); +failpoint.wait(); + +// Find the command opid and kill it. +const opId = + waitForCommand("dataSizeCmd", op => (op["command"]["dataSize"] == dbName + ".foo"), db); +assert.commandWorked(db.killOp(opId)); + +// The command is not killed just yet. It will be killed, after releasing the failpoint. +assert.neq(waitForCommand("dataSizeCmd", op => (op["command"]["dataSize"] == dbName + ".foo"), db), + -1); + +failpoint.off(); +awaitShell(); + +assert.commandWorked(db.dropDatabase()); +MongoRunner.stopMongod(conn); +})(); diff --git a/jstests/noPassthroughWithMongod/datasize_kill_op.js b/jstests/noPassthroughWithMongod/datasize_kill_op.js deleted file mode 100644 index e034aa630ed..00000000000 --- a/jstests/noPassthroughWithMongod/datasize_kill_op.js +++ /dev/null @@ -1,41 +0,0 @@ -// Test that the dataSize command can be interrupted. Failpoint is defined for mongod only, -// therefore this test is running only in unsharded setup. - -(function() { -"use strict"; - -load("jstests/libs/fail_point_util.js"); // For configureFailPoint. -load("jstests/libs/wait_for_command.js"); // For waitForCommand. -load("jstests/libs/parallel_shell_helpers.js"); // For funWithArgs. - -const coll = db.foo; -coll.drop(); -coll.insert({_id: 0, s: "asdasdasdasdasdasdasd"}); - -const dataSizeCommand = { - "dataSize": "test.foo", - "keyPattern": {"_id": 1}, - "min": {"_id": 0}, - "max": {"_id": 1} -}; - -// Configure the failpoint. -const failpoint = configureFailPoint(db, "hangBeforeDatasizeCount"); - -// Launch a parallel shell that runs the dataSize command, that should fail due to interrupt. -const awaitShell = - startParallelShell(funWithArgs(function(cmd) { - assert.commandFailedWithCode(db.runCommand(cmd), ErrorCodes.Interrupted); - }, dataSizeCommand), db.getMongo().port); -failpoint.wait(); - -// Find the command opid and kill it. -const opId = waitForCommand("dataSizeCmd", op => (op["command"]["dataSize"] == "test.foo"), db); -assert.commandWorked(db.killOp(opId)); - -// The command is not killed just yet. It will be killed, after releasing the failpoint. -assert.neq(waitForCommand("dataSizeCmd", op => (op["command"]["dataSize"] == "test.foo"), db), -1); - -failpoint.off(); -awaitShell(); -})(); -- cgit v1.2.1