jstests/sharding/query/javascript_heap_limit.js
/**
 * The following tests will execute JavaScript only on mongod. This is because $where and $expr are
 * only evaluated on mongod, not on mongos.
 */
The following tests will execute JavaScript only on mongod. This is because $where and $expr are
only evaluated on mongod, not on mongos.
The following tests will execute JavaScript only on mongod . This is because $where and $expr are only evaluated on mongod not on mongos .
function runShardTests(db) {
    setHeapSizeLimitMB({db: db, queryLimit: sufficentHeapSizeMB, globalLimit: sufficentHeapSizeMB});
    assert.commandWorked(db.runCommand(findWithJavaScriptFunction));
    assert.commandWorked(db.runCommand(mapReduce));
    setHeapSizeLimitMB({db: db, queryLimit: tooSmallHeapSizeMB, globalLimit: sufficentHeapSizeMB});
    assert.commandFailedWithCode(db.runCommand(findWithJavaScriptFunction),
                                 ErrorCodes.JSInterpreterFailure);
    setHeapSizeLimitMB({db: db, queryLimit: tooSmallHeapSizeMB, globalLimit: sufficentHeapSizeMB});
    assert.commandWorked(db.runCommand(mapReduce));
    setHeapSizeLimitMB({db: db, queryLimit: sufficentHeapSizeMB, globalLimit: tooSmallHeapSizeMB});
    assert.commandFailedWithCode(db.runCommand(findWithJavaScriptFunction),
                                 ErrorCodes.JSInterpreterFailure);
    assert.commandFailedWithCode(db.runCommand(mapReduce), ErrorCodes.JSInterpreterFailure);
}
function runShardTests ( db ) { setHeapSizeLimitMB ( { db : db , queryLimit : sufficentHeapSizeMB , globalLimit : sufficentHeapSizeMB } ) ; assert . commandWorked ( db . runCommand ( findWithJavaScriptFunction ) ) ; assert . commandWorked ( db . runCommand ( mapReduce ) ) ; setHeapSizeLimitMB ( { db : db , queryLimit : tooSmallHeapSizeMB , globalLimit : sufficentHeapSizeMB } ) ; assert . commandFailedWithCode ( db . runCommand ( findWithJavaScriptFunction ) , ErrorCodes . JSInterpreterFailure ) ; setHeapSizeLimitMB ( { db : db , queryLimit : tooSmallHeapSizeMB , globalLimit : sufficentHeapSizeMB } ) ; assert . commandWorked ( db . runCommand ( mapReduce ) ) ; setHeapSizeLimitMB ( { db : db , queryLimit : sufficentHeapSizeMB , globalLimit : tooSmallHeapSizeMB } ) ; assert . commandFailedWithCode ( db . runCommand ( findWithJavaScriptFunction ) , ErrorCodes . JSInterpreterFailure ) ; assert . commandFailedWithCode ( db . runCommand ( mapReduce ) , ErrorCodes . JSInterpreterFailure ) ; }
The following tests will execute JavaScript only on mongod.
The following tests will execute JavaScript only on mongod .
// All commands are expected to work with a sufficient JS heap size. // TODO SERVER-45454: Uncomment when $where is executed via  aggregation JavaScript expression. // assert.commandWorked(db.runCommand(findWithWhere)); // A find command with JavaScript agg expression is expected to fail when the query specific // heap size limit is too low. // The mapReduce command and $where are not limited by the query heap size limit and will // succeed even if it is set too low. // TODO SERVER-45454: Uncomment when $where is executed via  aggregation JavaScript expression. // assert.commandWorked(db.runCommand(findWithWhere)); // All commands are expected to fail when the global heap size limit is too low, regardless // of the aggregation limit. // TODO SERVER-45454: Uncomment when $where is executed via  aggregation JavaScript expression. // assert.commandFailedWithCode(db.runCommand(findWithWhere), ErrorCodes.JSInterpreterFailure);