jstests/noPassthrough/currentop_query.js
/**
     * Captures currentOp() for a given test command/operation and confirms that namespace,
     * operation type and planSummary are correct.
     *
     *  - 'testObj' - Contains test arguments.
     *  - 'testObj.test' - A function that runs the desired test op/cmd.
     *  - 'testObj.planSummary' - A string containing the expected planSummary.
     *  - 'testObj.currentOpFilter' - A filter to be used to narrow currentOp() output to only the
     *  relevant operation or command.
     *  - 'testObj.command]' - The command to test against. Will look for this to be a key in the
     *  currentOp().query object.
     *  - 'testObj.operation' - The operation to test against. Will look for this to be the value
     *  of the currentOp().op field.
     *  - 'testObj.skipMongosLocalOps' - True if this test should not be run against a mongos with
     *  localOps=true.
     */
Captures currentOp() for a given test command/operation and confirms that namespace,
operation type and planSummary are correct.

- 'testObj' - Contains test arguments.
- 'testObj.test' - A function that runs the desired test op/cmd.
- 'testObj.planSummary' - A string containing the expected planSummary.
- 'testObj.currentOpFilter' - A filter to be used to narrow currentOp() output to only the
relevant operation or command.
- 'testObj.command]' - The command to test against. Will look for this to be a key in the
currentOp().query object.
- 'testObj.operation' - The operation to test against. Will look for this to be the value
of the currentOp().op field.
- 'testObj.skipMongosLocalOps' - True if this test should not be run against a mongos with
localOps=true.
Captures currentOp () for a given test command / operation and confirms that namespace operation type and planSummary are correct . - ' testObj ' - Contains test arguments . - ' testObj . test ' - A function that runs the desired test op / cmd . - ' testObj . planSummary ' - A string containing the expected planSummary . - ' testObj . currentOpFilter ' - A filter to be used to narrow currentOp () output to only the relevant operation or command . - ' testObj . command ] ' - The command to test against . Will look for this to be a key in the currentOp () . query object . - ' testObj . operation ' - The operation to test against . Will look for this to be the value of the currentOp () . op field . - ' testObj . skipMongosLocalOps ' - True if this test should not be run against a mongos with localOps = true .
function confirmCurrentOpContents(testObj) {
        const skipMongosLocalOps = testObj.skipMongosLocalOps || false;
        if (isLocalMongosCurOp && skipMongosLocalOps) {
            return;
        }
        FixtureHelpers.runCommandOnEachPrimary({
            db: conn.getDB("admin"),
            cmdObj: {
                configureFailPoint: "setYieldAllLocksHang",
                mode: "alwaysOn",
                data: {namespace: mongosColl.getFullName()}
            }
        });
        TestData.currentOpTest = testObj.test;
        TestData.currentOpCollName = "currentop_query";
        function doTest() {
            const testDB = db.getSiblingDB(TestData.currentOpCollName);
            TestData.currentOpTest(testDB);
        }
        var awaitShell = startParallelShell(doTest, testDB.getMongo().port);
        if (!testObj.currentOpFilter.ns) {
            testObj.currentOpFilter.ns = coll.getFullName();
        }
        if (!isLocalMongosCurOp) {
            testObj.currentOpFilter.planSummary = testObj.planSummary;
        }
        if (testObj.hasOwnProperty("command")) {
            testObj.currentOpFilter["command." + testObj.command] = {$exists: true};
        } else if (testObj.hasOwnProperty("operation")) {
            testObj.currentOpFilter.op = testObj.operation;
        }
        assert.soon(
            function() {
                var result = currentOp(testDB, testObj.currentOpFilter, truncatedOps, localOps);
                assert.commandWorked(result);
                if (result.inprog.length > 0) {
                    result.inprog.forEach((op) => {
                        assert.eq(op.appName, "MongoDB Shell", tojson(result));
                        assert.eq(
                            op.clientMetadata.application.name, "MongoDB Shell", tojson(result));
                    });
                    return true;
                }
                return false;
            },
            function() {
                return "Failed to find operation from " + tojson(testObj.currentOpFilter) +
                    " in currentOp() output: " +
                    tojson(currentOp(testDB, {}, truncatedOps, localOps)) +
                    (isLocalMongosCurOp ? ", with localOps=false: " +
                             tojson(currentOp(testDB, {}, truncatedOps, false))
                                        : "");
            });
        FixtureHelpers.runCommandOnEachPrimary({
            db: conn.getDB("admin"),
            cmdObj: {configureFailPoint: "setYieldAllLocksHang", mode: "off"}
        });
        awaitShell();
        delete TestData.currentOpCollName;
        delete TestData.currentOpTest;
    }
function confirmCurrentOpContents ( testObj ) { const skipMongosLocalOps = testObj . skipMongosLocalOps || false ; if ( isLocalMongosCurOp && skipMongosLocalOps ) { return ; } FixtureHelpers . runCommandOnEachPrimary ( { db : conn . getDB ( "admin" ) , cmdObj : { configureFailPoint : "setYieldAllLocksHang" , mode : "alwaysOn" , data : { namespace : mongosColl . getFullName ( ) } } } ) ; TestData . currentOpTest = testObj . test ; TestData . currentOpCollName = "currentop_query" ; function doTest ( ) { const testDB = db . getSiblingDB ( TestData . currentOpCollName ) ; TestData . currentOpTest ( testDB ) ; } var awaitShell = startParallelShell ( doTest , testDB . getMongo ( ) . port ) ; if ( ! testObj . currentOpFilter . ns ) { testObj . currentOpFilter . ns = coll . getFullName ( ) ; } if ( ! isLocalMongosCurOp ) { testObj . currentOpFilter . planSummary = testObj . planSummary ; } if ( testObj . hasOwnProperty ( "command" ) ) { testObj . currentOpFilter [ "command." + testObj . command ] = { $exists : true } ; } else if ( testObj . hasOwnProperty ( "operation" ) ) { testObj . currentOpFilter . op = testObj . operation ; } assert . soon ( function ( ) { var result = currentOp ( testDB , testObj . currentOpFilter , truncatedOps , localOps ) ; assert . commandWorked ( result ) ; if ( result . inprog . length > 0 ) { result . inprog . forEach ( ( op ) => { assert . eq ( op . appName , "MongoDB Shell" , tojson ( result ) ) ; assert . eq ( op . clientMetadata . application . name , "MongoDB Shell" , tojson ( result ) ) ; } ) ; return true ; } return false ; } , function ( ) { return "Failed to find operation from " + tojson ( testObj . currentOpFilter ) + " in currentOp() output: " + tojson ( currentOp ( testDB , { } , truncatedOps , localOps ) ) + ( isLocalMongosCurOp ? ", with localOps=false: " + tojson ( currentOp ( testDB , { } , truncatedOps , false ) ) : "" ) ; } ) ; FixtureHelpers . runCommandOnEachPrimary ( { db : conn . getDB ( "admin" ) , cmdObj : { configureFailPoint : "setYieldAllLocksHang" , mode : "off" } } ) ; awaitShell ( ) ; delete TestData . currentOpCollName ; delete TestData . currentOpTest ; }
Captures currentOp() for a given test command/operation and confirms that namespace,
 operation type and planSummary are correct.
Captures currentOp () for a given test command / operation and confirms that namespace operation type and planSummary are correct .
// Force queries to hang on yield to allow for currentOp capture. // Set the test configuration in TestData for the parallel shell test. // Wrapper function which sets DB before running the test function // found at TestData.currentOpTest. // Run the operation in the background. // Augment the currentOpFilter with additional known predicates. // Capture currentOp record for the query and confirm that the 'query' and 'planSummary' // fields contain the content expected. We are indirectly testing the 'ns' field as well // with the currentOp query argument. // Allow the query to complete.