jstests/libs/analyze_plan.js
/**
 * Runs explain() operation on 'cmdObj' and verifies that all the stages in 'expectedStages' are
 * present exactly once in the plan returned. When 'stagesNotExpected' array is passed, also
 * verifies that none of those stages are present in the explain() plan.
 */
Runs explain() operation on 'cmdObj' and verifies that all the stages in 'expectedStages' are
present exactly once in the plan returned. When 'stagesNotExpected' array is passed, also
verifies that none of those stages are present in the explain() plan.
Runs explain () operation on ' cmdObj ' and verifies that all the stages in ' expectedStages ' are present exactly once in the plan returned . When ' stagesNotExpected ' array is passed also verifies that none of those stages are present in the explain () plan .
function assertStagesForExplainOfCommand({coll, cmdObj, expectedStages, stagesNotExpected}) {
    const plan = assert.commandWorked(coll.runCommand({explain: cmdObj}));
    const winningPlan = getWinningPlan(plan.queryPlanner);
    for (let expectedStage of expectedStages) {
        assert(planHasStage(coll.getDB(), winningPlan, expectedStage),
               "Could not find stage " + expectedStage + ". Plan: " + tojson(plan));
    }
    for (let stage of (stagesNotExpected || [])) {
        assert(!planHasStage(coll.getDB(), winningPlan, stage),
               "Found stage " + stage + " when not expected. Plan: " + tojson(plan));
    }
    return plan;
}
function assertStagesForExplainOfCommand ( { coll , cmdObj , expectedStages , stagesNotExpected } ) { const plan = assert . commandWorked ( coll . runCommand ( { explain : cmdObj } ) ) ; const winningPlan = getWinningPlan ( plan . queryPlanner ) ; for ( let expectedStage of expectedStages ) { assert ( planHasStage ( coll . getDB ( ) , winningPlan , expectedStage ) , "Could not find stage " + expectedStage + ". Plan: " + tojson ( plan ) ) ; } for ( let stage of ( stagesNotExpected || [ ] ) ) { assert ( ! planHasStage ( coll . getDB ( ) , winningPlan , stage ) , "Found stage " + stage + " when not expected. Plan: " + tojson ( plan ) ) ; } return plan ; }
Runs explain() operation on 'cmdObj' and verifies that all the stages in 'expectedStages' are
 present exactly once in the plan returned.
Runs explain () operation on ' cmdObj ' and verifies that all the stages in ' expectedStages ' are present exactly once in the plan returned .