2020-10-21 19:41:11 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { spawnSync } = require('child_process');
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const fs = require('fs');
|
|
|
|
const env = {
|
|
|
|
...process.env,
|
2023-02-12 16:36:39 +00:00
|
|
|
NODE_DEBUG_NATIVE: 'diagnostics',
|
2020-10-21 19:41:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!common.enoughTestMem)
|
|
|
|
common.skip('Insufficient memory for snapshot test');
|
|
|
|
|
|
|
|
{
|
|
|
|
console.log('\nTesting limit = 3');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const child = spawnSync(process.execPath, [
|
|
|
|
'--heapsnapshot-near-heap-limit=3',
|
|
|
|
'--max-old-space-size=512',
|
2021-03-26 15:51:08 +00:00
|
|
|
fixtures.path('workload', 'grow.js'),
|
2020-10-21 19:41:11 +00:00
|
|
|
], {
|
|
|
|
cwd: tmpdir.path,
|
|
|
|
env: {
|
|
|
|
...env,
|
|
|
|
TEST_CHUNK: 2000,
|
2023-02-12 16:36:39 +00:00
|
|
|
},
|
2020-10-21 19:41:11 +00:00
|
|
|
});
|
|
|
|
const stderr = child.stderr.toString();
|
|
|
|
console.log(stderr);
|
|
|
|
assert(common.nodeProcessAborted(child.status, child.signal),
|
|
|
|
'process should have aborted, but did not');
|
|
|
|
const list = fs.readdirSync(tmpdir.path)
|
|
|
|
.filter((file) => file.endsWith('.heapsnapshot'));
|
2021-03-15 19:44:04 +00:00
|
|
|
const risky = [...stderr.matchAll(
|
|
|
|
/Not generating snapshots because it's too risky/g)].length;
|
|
|
|
assert(list.length + risky > 0 && list.length <= 3,
|
|
|
|
`Generated ${list.length} snapshots ` +
|
|
|
|
`and ${risky} was too risky`);
|
2020-10-21 19:41:11 +00:00
|
|
|
}
|