test: account for OOM risks in heapsnapshot-near-heap-limit tests

PR-URL: https://github.com/nodejs/node/pull/37761
Fixes: https://github.com/nodejs/node/issues/36961
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Joyee Cheung authored and Ruy Adorno committed 2021-03-23 21:15:06 -04:00
1 parent a5205819d8
commit 9f61cbd1fd
3 files changed
+29 -17

No files matched your search

@@ -26,11 +26,14 @@ const env = {
console.log(child.stdout.toString());
const stderr = child.stderr.toString();
console.log(stderr);
// There should be one snapshot taken and then after the
// snapshot heap limit callback is popped, the OOM callback
// becomes effective.
assert(stderr.includes('ERR_WORKER_OUT_OF_MEMORY'));
const list = fs.readdirSync(tmpdir.path)
.filter((file) => file.endsWith('.heapsnapshot'));
assert.strictEqual(list.length, 1);
const risky = /Not generating snapshots because it's too risky/.test(stderr);
if (!risky) {
// There should be one snapshot taken and then after the
// snapshot heap limit callback is popped, the OOM callback
// becomes effective.
assert(stderr.includes('ERR_WORKER_OUT_OF_MEMORY'));
const list = fs.readdirSync(tmpdir.path)
.filter((file) => file.endsWith('.heapsnapshot'));
assert.strictEqual(list.length, 1);
}
}
@@ -58,12 +58,17 @@ const env = {
env,
});
console.log(child.stdout.toString());
console.log(child.stderr.toString());
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'));
assert.strictEqual(list.length, 1);
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`);
}
{
@@ -79,10 +84,15 @@ const env = {
env,
});
console.log(child.stdout.toString());
console.log(child.stderr.toString());
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'));
assert(list.length > 0 && list.length <= 3);
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`);
}
@@ -34,10 +34,9 @@ if (!common.enoughTestMem)
'process should have aborted, but did not');
const list = fs.readdirSync(tmpdir.path)
.filter((file) => file.endsWith('.heapsnapshot'));
if (list.length === 0) {
assert(stderr.includes(
'Not generating snapshots because it\'s too risky'));
} else {
assert(list.length > 0 && list.length <= 3);
}
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`);
}