diff --git a/test/parallel/test-external-memory-reasonable-size.js b/test/parallel/test-external-memory-reasonable-size.js index f9ff1af8e5a1..2d79eec892c1 100644 --- a/test/parallel/test-external-memory-reasonable-size.js +++ b/test/parallel/test-external-memory-reasonable-size.js @@ -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'), + }); }