jstests/aggregation/sources/setWindowFields/explain.js
/**
 * Checks that the execution stats in the explain output for a $setWindowFields stage are as
 * expected.
 * - 'stages' is an array of the explain output of $setWindowFields stages.
 * - 'expectedFunctionMemUsages' is used to check the memory footprint stats for each function.
 * - 'expectedTotalMemUsage' is used to check the peak memory footprint for the entire stage.
 * - 'verbosity' indicates the explain verbosity used.
 */
Checks that the execution stats in the explain output for a $setWindowFields stage are as
expected.
- 'stages' is an array of the explain output of $setWindowFields stages.
- 'expectedFunctionMemUsages' is used to check the memory footprint stats for each function.
- 'expectedTotalMemUsage' is used to check the peak memory footprint for the entire stage.
- 'verbosity' indicates the explain verbosity used.
Checks that the execution stats in the explain output for a $setWindowFields stage are as expected . - ' stages ' is an array of the explain output of $setWindowFields stages . - ' expectedFunctionMemUsages ' is used to check the memory footprint stats for each function . - ' expectedTotalMemUsage ' is used to check the peak memory footprint for the entire stage . - ' verbosity ' indicates the explain verbosity used .
function checkExplainResult(pipeline, expectedFunctionMemUsages, expectedTotalMemUsage, verbosity) {
    const stages =
        getAggPlanStages(coll.explain(verbosity).aggregate(pipeline), "$_internalSetWindowFields");
    for (let stage of stages) {
        assert(stage.hasOwnProperty("$_internalSetWindowFields"), stage);
        if (verbosity === "executionStats" || verbosity === "allPlansExecution") {
            assert(stage.hasOwnProperty("maxFunctionMemoryUsageBytes"), stage);
            const maxFunctionMemUsages = stage["maxFunctionMemoryUsageBytes"];
            for (let field of Object.keys(maxFunctionMemUsages)) {
                if (expectedFunctionMemUsages.hasOwnProperty(field)) {
                    assert.gte(maxFunctionMemUsages[field],
                               expectedFunctionMemUsages[field] * .9,
                               "mismatch for function '" + field + "': " + tojson(stage));
                    assert.lt(maxFunctionMemUsages[field],
                              2.2 * expectedFunctionMemUsages[field],
                              "mismatch for function '" + field + "': " + tojson(stage));
                }
            }
            assert.gt(stage["maxTotalMemoryUsageBytes"],
                      expectedTotalMemUsage * .9,
                      "Incorrect total mem usage: " + tojson(stage));
            assert.lt(stage["maxTotalMemoryUsageBytes"],
                      2.2 * expectedTotalMemUsage,
                      "Incorrect total mem usage: " + tojson(stage));
        } else {
            assert(!stage.hasOwnProperty("maxFunctionMemoryUsageBytes"), stage);
            assert(!stage.hasOwnProperty("maxTotalMemoryUsageBytes"), stage);
        }
    }
}
function checkExplainResult ( pipeline , expectedFunctionMemUsages , expectedTotalMemUsage , verbosity ) { const stages = getAggPlanStages ( coll . explain ( verbosity ) . aggregate ( pipeline ) , "$_internalSetWindowFields" ) ; for ( let stage of stages ) { assert ( stage . hasOwnProperty ( "$_internalSetWindowFields" ) , stage ) ; if ( verbosity === "executionStats" || verbosity === "allPlansExecution" ) { assert ( stage . hasOwnProperty ( "maxFunctionMemoryUsageBytes" ) , stage ) ; const maxFunctionMemUsages = stage [ "maxFunctionMemoryUsageBytes" ] ; for ( let field of Object . keys ( maxFunctionMemUsages ) ) { if ( expectedFunctionMemUsages . hasOwnProperty ( field ) ) { assert . gte ( maxFunctionMemUsages [ field ] , expectedFunctionMemUsages [ field ] * .9 , "mismatch for function '" + field + "': " + tojson ( stage ) ) ; assert . lt ( maxFunctionMemUsages [ field ] , 2.2 * expectedFunctionMemUsages [ field ] , "mismatch for function '" + field + "': " + tojson ( stage ) ) ; } } assert . gt ( stage [ "maxTotalMemoryUsageBytes" ] , expectedTotalMemUsage * .9 , "Incorrect total mem usage: " + tojson ( stage ) ) ; assert . lt ( stage [ "maxTotalMemoryUsageBytes" ] , 2.2 * expectedTotalMemUsage , "Incorrect total mem usage: " + tojson ( stage ) ) ; } else { assert ( ! stage . hasOwnProperty ( "maxFunctionMemoryUsageBytes" ) , stage ) ; assert ( ! stage . hasOwnProperty ( "maxTotalMemoryUsageBytes" ) , stage ) ; } } }
Checks that the execution stats in the explain output for a $setWindowFields stage are as
 expected.
Checks that the execution stats in the explain output for a $setWindowFields stage are as expected .
// Ensures that the expected functions are all included and the corresponding // memory usage is in a reasonable range. // The estimates being passed in are as close as possible to accurate. Leave 10% // wiggle room for variants that use different amounts of memory.