Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions test/parallel/test-external-memory-reasonable-size.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
'use strict';

// V8 aborts the process when external memory grows by more than
// --external-memory-max-reasonable-size gigabytes in a single step. Node
// disables that check by default, but an explicit value on the command line
// must still be honored.
// Node.js disables V8's external memory reasonable size check by default, but
// explicit values on the command line must still be honored.
// Refs: https://github.com/nodejs/node/issues/65534

const common = require('../common');
const assert = require('assert');
const { execSync } = require('child_process');
const { totalmem } = require('os');
require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');

// The smallest limit V8 accepts is 1 GB, so the child has to allocate more
// than that before the check can fire.
if (totalmem() < 4 * 1024 ** 3)
common.skip('not enough memory to exceed a 1 GB external memory limit');

for (const flag of [
'--external-memory-max-reasonable-size=1',
'--external_memory_max_reasonable_size=1',
// Despite the "default" label, --v8-options prints the parsed flag values.
for (const [flags, expected] of [
[[], 0],
[['--external-memory-max-reasonable-size=1'], 1],
[['--external_memory_max_reasonable_size=1'], 1],
]) {
// The child aborts with over a gigabyte resident, so keep it from writing a
// core file; on some hosts that dump alone outlasts the test timeout.
const [cmd, opts] = common.escapePOSIXShell`"${process.execPath}" ${flag} -e "new Float64Array(150_000_000)"`;
assert.throws(
() => execSync(common.isWindows ? cmd : `ulimit -c 0; ${cmd}`, { ...opts, stdio: 'pipe' }),
(err) => {
assert.notStrictEqual(err.status, 0, `${flag} was not honored, the child exited cleanly`);
assert.match(err.stderr.toString(), /kMaxReasonableBytes/);
return true;
},
);
spawnSyncAndAssert(process.execPath, [...flags, '--v8-options'], {
stdout: new RegExp(`default: --external-memory-max-reasonable-size=${expected}$`, 'm'),
});
}
Loading