jstests/sharding/query/javascript_heap_limit.js
/**
 * The following tests will execute JavaScript on the process represented by 'db' regardless of
 * whether it is a mongod or mongos. This is because the JavaScript expressions live in the merger
 * part of an aggregation pipeline.
 */
The following tests will execute JavaScript on the process represented by 'db' regardless of
whether it is a mongod or mongos. This is because the JavaScript expressions live in the merger
part of an aggregation pipeline.
The following tests will execute JavaScript on the process represented by ' db ' regardless of whether it is a mongod or mongos . This is because the JavaScript expressions live in the merger part of an aggregation pipeline .
function runCommonTests(db) {
    setHeapSizeLimitMB({db: db, queryLimit: sufficentHeapSizeMB, globalLimit: sufficentHeapSizeMB});
    assert.commandWorked(db.runCommand(aggregateWithJSFunction));
    assert.commandWorked(db.runCommand(aggregateWithInternalJsReduce));
    assert.commandWorked(db.runCommand(aggregateWithUserDefinedAccumulator));
    setHeapSizeLimitMB({db: db, queryLimit: tooSmallHeapSizeMB, globalLimit: sufficentHeapSizeMB});
    assert.commandFailedWithCode(db.runCommand(aggregateWithJSFunction),
                                 ErrorCodes.JSInterpreterFailure);
    assert.commandFailedWithCode(db.runCommand(aggregateWithInternalJsReduce),
                                 ErrorCodes.JSInterpreterFailure);
    assert.commandFailedWithCode(db.runCommand(aggregateWithUserDefinedAccumulator),
                                 ErrorCodes.JSInterpreterFailure);
    setHeapSizeLimitMB({db: db, queryLimit: sufficentHeapSizeMB, globalLimit: tooSmallHeapSizeMB});
    assert.commandFailedWithCode(db.runCommand(aggregateWithJSFunction),
                                 ErrorCodes.JSInterpreterFailure);
    assert.commandFailedWithCode(db.runCommand(aggregateWithInternalJsReduce),
                                 ErrorCodes.JSInterpreterFailure);
    assert.commandFailedWithCode(db.runCommand(aggregateWithUserDefinedAccumulator),
                                 ErrorCodes.JSInterpreterFailure);
}
function runCommonTests ( db ) { setHeapSizeLimitMB ( { db : db , queryLimit : sufficentHeapSizeMB , globalLimit : sufficentHeapSizeMB } ) ; assert . commandWorked ( db . runCommand ( aggregateWithJSFunction ) ) ; assert . commandWorked ( db . runCommand ( aggregateWithInternalJsReduce ) ) ; assert . commandWorked ( db . runCommand ( aggregateWithUserDefinedAccumulator ) ) ; setHeapSizeLimitMB ( { db : db , queryLimit : tooSmallHeapSizeMB , globalLimit : sufficentHeapSizeMB } ) ; assert . commandFailedWithCode ( db . runCommand ( aggregateWithJSFunction ) , ErrorCodes . JSInterpreterFailure ) ; assert . commandFailedWithCode ( db . runCommand ( aggregateWithInternalJsReduce ) , ErrorCodes . JSInterpreterFailure ) ; assert . commandFailedWithCode ( db . runCommand ( aggregateWithUserDefinedAccumulator ) , ErrorCodes . JSInterpreterFailure ) ; setHeapSizeLimitMB ( { db : db , queryLimit : sufficentHeapSizeMB , globalLimit : tooSmallHeapSizeMB } ) ; assert . commandFailedWithCode ( db . runCommand ( aggregateWithJSFunction ) , ErrorCodes . JSInterpreterFailure ) ; assert . commandFailedWithCode ( db . runCommand ( aggregateWithInternalJsReduce ) , ErrorCodes . JSInterpreterFailure ) ; assert . commandFailedWithCode ( db . runCommand ( aggregateWithUserDefinedAccumulator ) , ErrorCodes . JSInterpreterFailure ) ; }
The following tests will execute JavaScript on the process represented by 'db' regardless of
 whether it is a mongod or mongos.
The following tests will execute JavaScript on the process represented by ' db ' regardless of whether it is a mongod or mongos .
// All commands are expected to work with a sufficient JS heap size. // The aggregate command is expected to fail when the aggregation specific heap size limit is // too low. // All commands are expected to fail when the global heap size limit is too low, regardless // of the aggregation limit.