jstests/noPassthrough/interrupt_while_yielded.js
/**
 * Executes 'queryFn' in a parallel shell while a failpoint is enabled to hang operations during
 * yield. Ensures that operation run by 'queryFn' reaches the yield point, then runs killOp()
 * against the yielded operation.
 */
Executes 'queryFn' in a parallel shell while a failpoint is enabled to hang operations during
yield. Ensures that operation run by 'queryFn' reaches the yield point, then runs killOp()
against the yielded operation.
Executes ' queryFn ' in a parallel shell while a failpoint is enabled to hang operations during yield . Ensures that operation run by ' queryFn ' reaches the yield point then runs killOp () against the yielded operation .
function runTestWithQuery(queryFn) {
    let waitForParallelShell = null;
    try {
        assert.commandWorked(db.adminCommand({
            configureFailPoint: kFailPointName,
            mode: "alwaysOn",
            data: {namespace: coll.getFullName(), checkForInterruptAfterHang: true}
        }));
        let code = `let queryFn = ${queryFn};`;
        code += `const coll = db.${coll.getName()};`;
        code += `const kCommandComment = "${kCommandComment}";`;
        function parallelShellFn() {
            const err = assert.throws(queryFn);
            assert.commandFailedWithCode(err, [ErrorCodes.Interrupted]);
        }
        code += "(" + parallelShellFn.toString() + ")();";
        waitForParallelShell = startParallelShell(code, conn.port);
        let opId = null;
        assert.soon(function() {
            const ops = db.getSiblingDB("admin")
                            .aggregate([
                                {$currentOp: {allUsers: true, localOps: true}},
                                {
                                    $match: {
                                        numYields: {$gt: 0},
                                        ns: coll.getFullName(),
                                        "command.comment": kCommandComment
                                    }
                                }
                            ])
                            .toArray();
            if (ops.length > 0) {
                assert.eq(ops.length, 1);
                opId = ops[0].opid;
                return true;
            }
            return false;
        });
        db.killOp(opId);
    } finally {
        assert.commandWorked(db.adminCommand({configureFailPoint: kFailPointName, mode: "off"}));
        if (waitForParallelShell) {
            waitForParallelShell();
        }
    }
    assert.commandWorked(db.adminCommand({hello: 1}));
}
function runTestWithQuery ( queryFn ) { let waitForParallelShell = null ; try { assert . commandWorked ( db . adminCommand ( { configureFailPoint : kFailPointName , mode : "alwaysOn" , data : { namespace : coll . getFullName ( ) , checkForInterruptAfterHang : true } } ) ) ; let code = ` ${ queryFn } ` ; code += ` ${ coll . getName ( ) } ` ; code += ` ${ kCommandComment } ` ; function parallelShellFn ( ) { const err = assert . throws ( queryFn ) ; assert . commandFailedWithCode ( err , [ ErrorCodes . Interrupted ] ) ; } code += "(" + parallelShellFn . toString ( ) + ")();" ; waitForParallelShell = startParallelShell ( code , conn . port ) ; let opId = null ; assert . soon ( function ( ) { const ops = db . getSiblingDB ( "admin" ) . aggregate ( [ { $currentOp : { allUsers : true , localOps : true } } , { $match : { numYields : { $gt : 0 } , ns : coll . getFullName ( ) , "command.comment" : kCommandComment } } ] ) . toArray ( ) ; if ( ops . length > 0 ) { assert . eq ( ops . length , 1 ) ; opId = ops [ 0 ] . opid ; return true ; } return false ; } ) ; db . killOp ( opId ) ; } finally { assert . commandWorked ( db . adminCommand ( { configureFailPoint : kFailPointName , mode : "off" } ) ) ; if ( waitForParallelShell ) { waitForParallelShell ( ) ; } } assert . commandWorked ( db . adminCommand ( { hello : 1 } ) ) ; }
Executes 'queryFn' in a parallel shell while a failpoint is enabled to hang operations during
 yield.
Executes ' queryFn ' in a parallel shell while a failpoint is enabled to hang operations during yield .
// Run a command that should hit the fail point in a parallel shell. // Find the operation running the query. // Kill the op. // Disable the failpoint so that the server will continue, and hit an interrupt check. // Check that the server is still up.