jstests/noPassthrough/merge_max_time_ms.js
/**
 * Run a $merge 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 $merge aggregate against the node specified by 'conn' with primary 'primaryConn' (these may
be the same node).
Run a $merge aggregate against the node specified by ' conn ' with primary ' primaryConn ' ( these may be the same node ) .
function runUnshardedTest(whenMatched, whenNotMatched, conn, primaryConn, maxTimeMsConn) {
    jsTestLog("Running unsharded test in whenMatched: " + whenMatched +
              " whenNotMatched: " + whenNotMatched);
    if (whenNotMatched == "fail") {
        return;
    }
    const sourceColl = conn.getDB(kDBName)[kSourceCollName];
    const destColl = primaryConn.getDB(kDBName)[kDestCollName];
    assert.commandWorked(destColl.remove({}));
    (function() {
        const maxTimeMS = 1000 * 600;
        const pipeline = [{
            $merge:
                {into: destColl.getName(), whenMatched: whenMatched, whenNotMatched: whenNotMatched}
        }];
        assert.doesNotThrow(() => sourceColl.aggregate(pipeline, {maxTimeMS: maxTimeMS}));
    })();
    assert.commandWorked(destColl.remove({}));
    const kFailPointName =
        whenMatched === "fail" ? "hangDuringBatchInsert" : "hangDuringBatchUpdate";
    forceAggregationToHangAndCheckMaxTimeMsExpires(
        whenMatched, whenNotMatched, kFailPointName, conn, primaryConn, maxTimeMsConn);
    assert.commandWorked(destColl.remove({}));
    forceAggregationToHangAndCheckMaxTimeMsExpires(
        whenMatched, whenNotMatched, "hangWhileBuildingDocumentSourceMergeBatch", conn, conn, conn);
}
function runUnshardedTest ( whenMatched , whenNotMatched , conn , primaryConn , maxTimeMsConn ) { jsTestLog ( "Running unsharded test in whenMatched: " + whenMatched + " whenNotMatched: " + whenNotMatched ) ; if ( whenNotMatched == "fail" ) { return ; } const sourceColl = conn . getDB ( kDBName ) [ kSourceCollName ] ; const destColl = primaryConn . getDB ( kDBName ) [ kDestCollName ] ; assert . commandWorked ( destColl . remove ( { } ) ) ; ( function ( ) { const maxTimeMS = 1000 * 600 ; const pipeline = [ { $merge : { into : destColl . getName ( ) , whenMatched : whenMatched , whenNotMatched : whenNotMatched } } ] ; assert . doesNotThrow ( ( ) => sourceColl . aggregate ( pipeline , { maxTimeMS : maxTimeMS } ) ) ; } ) ( ) ; assert . commandWorked ( destColl . remove ( { } ) ) ; const kFailPointName = whenMatched === "fail" ? "hangDuringBatchInsert" : "hangDuringBatchUpdate" ; forceAggregationToHangAndCheckMaxTimeMsExpires ( whenMatched , whenNotMatched , kFailPointName , conn , primaryConn , maxTimeMsConn ) ; assert . commandWorked ( destColl . remove ( { } ) ) ; forceAggregationToHangAndCheckMaxTimeMsExpires ( whenMatched , whenNotMatched , "hangWhileBuildingDocumentSourceMergeBatch" , conn , conn , conn ) ; }
Run a $merge aggregate against the node specified by 'conn' with primary 'primaryConn' (these may
 be the same node).
Run a $merge aggregate against the node specified by ' conn ' with primary ' primaryConn ' ( these may be the same node ) .
// The target collection will always be empty so we do not test the setting that will cause // only failure. // 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. The failpoint changes // depending on the mode. If 'whenMatched' is set to "fail" then the implementation will end // up issuing insert commands instead of updates. // Force the aggregation to hang while the batch is being built.