jstests/noPassthrough/out_max_time_ms.js
/**
 * Run a $out aggregate against the node specified by 'conn' with primary 'primaryConn' (these may
 * be the same node). Verify that maxTimeMS properly times out the aggregate on the node specified
 * by 'maxTimeMsConn' both while hanging on the insert/update on 'primaryConn' and while hanging on
 * the batch being built on 'conn'.
 */
Run a $out aggregate against the node specified by 'conn' with primary 'primaryConn' (these may
be the same node).
Run a $out aggregate against the node specified by ' conn ' with primary ' primaryConn ' ( these may be the same node ) .
function runUnshardedTest(conn, primaryConn, maxTimeMsConn) {
    jsTestLog("Running unsharded test");
    const sourceColl = conn.getDB(kDBName)[kSourceCollName];
    const destColl = primaryConn.getDB(kDBName)[kDestCollName];
    assert.commandWorked(destColl.remove({}));
    (function() {
        const maxTimeMS = 1000 * 600;
        const pipeline = [{$out: destColl.getName()}];
        const cursor = sourceColl.aggregate(pipeline, {maxTimeMS: maxTimeMS});
        assert(!cursor.hasNext());
        assert.eq(destColl.countDocuments({_id: {$exists: true}}), nDocs);
    })();
    assert.commandWorked(destColl.remove({}));
    const kFailPointName = "hangDuringBatchInsert";
    forceAggregationToHangAndCheckMaxTimeMsExpires(
        kFailPointName, conn, primaryConn, maxTimeMsConn);
    assert.commandWorked(destColl.remove({}));
    forceAggregationToHangAndCheckMaxTimeMsExpires(
        "hangWhileBuildingDocumentSourceOutBatch", conn, conn, conn);
}
function runUnshardedTest ( conn , primaryConn , maxTimeMsConn ) { jsTestLog ( "Running unsharded test" ) ; const sourceColl = conn . getDB ( kDBName ) [ kSourceCollName ] ; const destColl = primaryConn . getDB ( kDBName ) [ kDestCollName ] ; assert . commandWorked ( destColl . remove ( { } ) ) ; ( function ( ) { const maxTimeMS = 1000 * 600 ; const pipeline = [ { $out : destColl . getName ( ) } ] ; const cursor = sourceColl . aggregate ( pipeline , { maxTimeMS : maxTimeMS } ) ; assert ( ! cursor . hasNext ( ) ) ; assert . eq ( destColl . countDocuments ( { _id : { $exists : true } } ) , nDocs ) ; } ) ( ) ; assert . commandWorked ( destColl . remove ( { } ) ) ; const kFailPointName = "hangDuringBatchInsert" ; forceAggregationToHangAndCheckMaxTimeMsExpires ( kFailPointName , conn , primaryConn , maxTimeMsConn ) ; assert . commandWorked ( destColl . remove ( { } ) ) ; forceAggregationToHangAndCheckMaxTimeMsExpires ( "hangWhileBuildingDocumentSourceOutBatch" , conn , conn , conn ) ; }
Run a $out aggregate against the node specified by 'conn' with primary 'primaryConn' (these may
 be the same node).
Run a $out aggregate against the node specified by ' conn ' with primary ' primaryConn ' ( these may be the same node ) .
// Be sure we're able to read from a cursor with a maxTimeMS set on it. // Use a long maxTimeMS, since we expect the operation to finish. // Force the aggregation to hang while the batch is being written. // Force the aggregation to hang while the batch is being built.