2017-06-24 15:37:59 -04:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
|
|
|
|
// This test ensures that an out of memory error exits with code 134 on Windows
|
|
|
|
|
|
|
|
if (!common.isWindows) return common.skip('Windows-only');
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
if (process.argv[2] === 'heapBomb') {
|
2019-01-21 01:22:27 +01:00
|
|
|
// Heap bomb, imitates a memory leak quickly
|
2017-09-13 14:43:43 +02:00
|
|
|
const fn = (nM) => [...Array(nM)].map((i) => fn(nM * 2));
|
2017-06-24 15:37:59 -04:00
|
|
|
fn(2);
|
|
|
|
}
|
|
|
|
|
2019-12-13 00:28:24 +01:00
|
|
|
// Run child in tmpdir to avoid report files in repo
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
|
2017-06-24 15:37:59 -04:00
|
|
|
// --max-old-space-size=3 is the min 'old space' in V8, explodes fast
|
2022-01-26 19:56:47 +02:00
|
|
|
const cmd = `"${process.execPath}" --max-old-space-size=30 "${__filename}"`;
|
|
|
|
exec(`${cmd} heapBomb`, { cwd: tmpdir.path }, common.mustCall((err, stdout, stderr) => {
|
2017-06-24 15:37:59 -04:00
|
|
|
const msg = `Wrong exit code of ${err.code}! Expected 134 for abort`;
|
|
|
|
// Note: common.nodeProcessAborted() is not asserted here because it
|
2021-05-19 18:20:56 +02:00
|
|
|
// returns true on 134 as well as 0x80000003 (V8's base::OS::Abort)
|
2017-06-24 15:37:59 -04:00
|
|
|
assert.strictEqual(err.code, 134, msg);
|
|
|
|
}));
|