node/test/parallel/test-windows-failed-heap-allocation.js
Gerhard Stoebich b2bfacb914
test: avoid leftover report file
test-windows-failed-heap-allocation forces a out of mem crash resulting
in a report file. To avoid a leftover in repo the child is started in a
tmp folder like in test-report-fatal-error.

PR-URL: https://github.com/nodejs/node/pull/30925
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-12-15 14:54:36 +01:00

29 lines
1023 B
JavaScript

'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') {
// Heap bomb, imitates a memory leak quickly
const fn = (nM) => [...Array(nM)].map((i) => fn(nM * 2));
fn(2);
}
// Run child in tmpdir to avoid report files in repo
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// --max-old-space-size=3 is the min 'old space' in V8, explodes fast
const cmd = `"${process.execPath}" --max-old-space-size=3 "${__filename}"`;
exec(`${cmd} heapBomb`, { cwd: tmpdir.path }, common.mustCall((err) => {
const msg = `Wrong exit code of ${err.code}! Expected 134 for abort`;
// Note: common.nodeProcessAborted() is not asserted here because it
// returns true on 134 as well as 0xC0000005 (V8's base::OS::Abort)
assert.strictEqual(err.code, 134, msg);
}));