forked from nodejs/node
/
test-worker-max-old-space-size.js
35 lines (32 loc) · 1.19 KB
/
test-worker-max-old-space-size.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Flags: --thread-max-old-space-size=1024
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker, resourceLimits } = require('worker_threads');
const { allocateUntilCrash } = require('../common/allocate-and-check-limits');
const testResourceLimits = {
maxOldGenerationSizeMb: 16,
maxYoungGenerationSizeMb: 4,
codeRangeSizeMb: 16,
stackSizeMb: 1,
};
// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const w = new Worker(__filename, { resourceLimits: testResourceLimits });
assert.deepStrictEqual(w.resourceLimits, testResourceLimits);
w.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.deepStrictEqual(w.resourceLimits, {});
}));
w.on('error', common.expectsError({
code: 'ERR_WORKER_OUT_OF_MEMORY',
message: 'Worker terminated due to reaching memory limit: ' +
'JS heap out of memory'
}));
return;
}
assert.deepStrictEqual(resourceLimits, testResourceLimits);
// resourceLimits should be used; --thread-max-old-space-size should only
// affect the main thread.
allocateUntilCrash(resourceLimits);