summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/low_js_heap_limit.js
blob: 7ef5d99d5830ccfc43089bc68ed440b9f6c39d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// SERVER-26596 This tests that you can set a very low heap limit for javascript, and that it will
// fail to run any javascript, but won't crash the server.
(function() {
    'use strict';

    const conn = MongoRunner.runMongod();
    var db = conn.getDB('db');

    assert.commandWorked(db.adminCommand({setParameter: 1, jsHeapLimitMB: 1}));

    db.foo.insert({x: 1});
    const e = assert.throws(() => db.foo.findOne({$where: 'sleep(10000);'}));
    assert.eq(e.code, ErrorCodes.ExceededMemoryLimit);

    var returnCode = runProgram("mongo", "--jsHeapLimitMB=1", "--nodb", "--eval='exit();'");
    assert.eq(returnCode, 1);
    MongoRunner.stopMongod(conn);
}());