jstests/noPassthrough/out_max_time_ms.js
/**
 * Given a mongod connection, run a $out aggregation against 'conn'. Set the provided failpoint on
 * the node specified by 'failPointConn' in order to hang during the aggregate. Ensure that the $out
 * maxTimeMS expires on the node specified by 'maxTimeMsConn'.
 */
Given a mongod connection, run a $out aggregation against 'conn'. Set the provided failpoint on
the node specified by 'failPointConn' in order to hang during the aggregate. Ensure that the $out
maxTimeMS expires on the node specified by 'maxTimeMsConn'.
Given a mongod connection run a $out aggregation against ' conn ' . Set the provided failpoint on the node specified by ' failPointConn ' in order to hang during the aggregate . Ensure that the $out maxTimeMS expires on the node specified by ' maxTimeMsConn ' .
function forceAggregationToHangAndCheckMaxTimeMsExpires(
    failPointName, conn, failPointConn, maxTimeMsConn) {
    const maxTimeMS = 1000 * 2;
    const failpointCommand = {
        configureFailPoint: failPointName,
        mode: "alwaysOn",
    };
    assert.commandWorked(failPointConn.getDB("admin").runCommand(failpointCommand));
    prohibitMaxTimeExpiration();
    let shellStr = `const testDB = db.getSiblingDB('${kDBName}');`;
    shellStr += `const sourceColl = testDB['${kSourceCollName}'];`;
    shellStr += `const destColl = testDB['${kDestCollName}'];`;
    shellStr += `const maxTimeMS = ${maxTimeMS};`;
    const runAggregate = function() {
        const pipeline = [{$out: destColl.getName()}];
        const err = assert.throws(
            () => sourceColl.aggregate(
                pipeline, {maxTimeMS: maxTimeMS, $readPreference: {mode: "secondary"}}));
        assert.eq(err.code, ErrorCodes.MaxTimeMSExpired, "expected aggregation to fail");
    };
    shellStr += `(${runAggregate.toString()})();`;
    const awaitShell = startParallelShell(shellStr, conn.port);
    waitForCurOpByFailPointNoNS(failPointConn.getDB("admin"), failPointName);
    assert.commandWorked(maxTimeMsConn.getDB("admin").runCommand(
        {configureFailPoint: "maxTimeNeverTimeOut", mode: "off"}));
    sleep(maxTimeMS + 2000);
    assert.commandWorked(
        failPointConn.getDB("admin").runCommand({configureFailPoint: failPointName, mode: "off"}));
    assert.eq(awaitShell(), 0);
}
function forceAggregationToHangAndCheckMaxTimeMsExpires ( failPointName , conn , failPointConn , maxTimeMsConn ) { const maxTimeMS = 1000 * 2 ; const failpointCommand = { configureFailPoint : failPointName , mode : "alwaysOn" , } ; assert . commandWorked ( failPointConn . getDB ( "admin" ) . runCommand ( failpointCommand ) ) ; prohibitMaxTimeExpiration ( ) ; let shellStr = ` ${ kDBName } ` ; shellStr += ` ${ kSourceCollName } ` ; shellStr += ` ${ kDestCollName } ` ; shellStr += ` ${ maxTimeMS } ` ; const runAggregate = function ( ) { const pipeline = [ { $out : destColl . getName ( ) } ] ; const err = assert . throws ( ( ) => sourceColl . aggregate ( pipeline , { maxTimeMS : maxTimeMS , $readPreference : { mode : "secondary" } } ) ) ; assert . eq ( err . code , ErrorCodes . MaxTimeMSExpired , "expected aggregation to fail" ) ; } ; shellStr += ` ${ runAggregate . toString ( ) } ` ; const awaitShell = startParallelShell ( shellStr , conn . port ) ; waitForCurOpByFailPointNoNS ( failPointConn . getDB ( "admin" ) , failPointName ) ; assert . commandWorked ( maxTimeMsConn . getDB ( "admin" ) . runCommand ( { configureFailPoint : "maxTimeNeverTimeOut" , mode : "off" } ) ) ; sleep ( maxTimeMS + 2000 ) ; assert . commandWorked ( failPointConn . getDB ( "admin" ) . runCommand ( { configureFailPoint : failPointName , mode : "off" } ) ) ; assert . eq ( awaitShell ( ) , 0 ) ; }
Given a mongod connection, run a $out aggregation against 'conn'.
Given a mongod connection run a $out aggregation against ' conn ' .
// Use a short maxTimeMS so that the test completes in a reasonable amount of time. We will // use the 'maxTimeNeverTimeOut' failpoint to ensure that the operation does not prematurely // time out. // Enable a failPoint so that the write will hang. // Make sure we don't run out of time on any of the involved nodes before the failpoint is hit. // Build the parallel shell function. // The aggregation running in the parallel shell will hang on the failpoint, burning // its time. Wait until the maxTimeMS has definitely expired. // Now drop the failpoint, allowing the aggregation to proceed. It should hit an // interrupt check and terminate immediately. // Wait for the parallel shell to finish.