Skip to content

Commit 9f61cbd

Browse files
joyeecheungruyadorno
authored andcommitted
test: account for OOM risks in heapsnapshot-near-heap-limit tests
PR-URL: #37761 Fixes: #36961 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent a520581 commit 9f61cbd

3 files changed

+29
-17
lines changed

test/parallel/test-heapsnapshot-near-heap-limit-worker.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ const env = {
2626
console.log(child.stdout.toString());
2727
const stderr = child.stderr.toString();
2828
console.log(stderr);
29-
// There should be one snapshot taken and then after the
30-
// snapshot heap limit callback is popped, the OOM callback
31-
// becomes effective.
32-
assert(stderr.includes('ERR_WORKER_OUT_OF_MEMORY'));
33-
const list = fs.readdirSync(tmpdir.path)
34-
.filter((file) => file.endsWith('.heapsnapshot'));
35-
assert.strictEqual(list.length, 1);
29+
const risky = /Not generating snapshots because it's too risky/.test(stderr);
30+
if (!risky) {
31+
// There should be one snapshot taken and then after the
32+
// snapshot heap limit callback is popped, the OOM callback
33+
// becomes effective.
34+
assert(stderr.includes('ERR_WORKER_OUT_OF_MEMORY'));
35+
const list = fs.readdirSync(tmpdir.path)
36+
.filter((file) => file.endsWith('.heapsnapshot'));
37+
assert.strictEqual(list.length, 1);
38+
}
3639
}

test/parallel/test-heapsnapshot-near-heap-limit.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ const env = {
5858
env,
5959
});
6060
console.log(child.stdout.toString());
61-
console.log(child.stderr.toString());
61+
const stderr = child.stderr.toString();
62+
console.log(stderr);
6263
assert(common.nodeProcessAborted(child.status, child.signal),
6364
'process should have aborted, but did not');
6465
const list = fs.readdirSync(tmpdir.path)
6566
.filter((file) => file.endsWith('.heapsnapshot'));
66-
assert.strictEqual(list.length, 1);
67+
const risky = [...stderr.matchAll(
68+
/Not generating snapshots because it's too risky/g)].length;
69+
assert(list.length + risky > 0 && list.length <= 3,
70+
`Generated ${list.length} snapshots ` +
71+
`and ${risky} was too risky`);
6772
}
6873

6974
{
@@ -79,10 +84,15 @@ const env = {
7984
env,
8085
});
8186
console.log(child.stdout.toString());
82-
console.log(child.stderr.toString());
87+
const stderr = child.stderr.toString();
88+
console.log(stderr);
8389
assert(common.nodeProcessAborted(child.status, child.signal),
8490
'process should have aborted, but did not');
8591
const list = fs.readdirSync(tmpdir.path)
8692
.filter((file) => file.endsWith('.heapsnapshot'));
87-
assert(list.length > 0 && list.length <= 3);
93+
const risky = [...stderr.matchAll(
94+
/Not generating snapshots because it's too risky/g)].length;
95+
assert(list.length + risky > 0 && list.length <= 3,
96+
`Generated ${list.length} snapshots ` +
97+
`and ${risky} was too risky`);
8898
}

test/pummel/test-heapsnapshot-near-heap-limit-big.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ if (!common.enoughTestMem)
3434
'process should have aborted, but did not');
3535
const list = fs.readdirSync(tmpdir.path)
3636
.filter((file) => file.endsWith('.heapsnapshot'));
37-
if (list.length === 0) {
38-
assert(stderr.includes(
39-
'Not generating snapshots because it\'s too risky'));
40-
} else {
41-
assert(list.length > 0 && list.length <= 3);
42-
}
37+
const risky = [...stderr.matchAll(
38+
/Not generating snapshots because it's too risky/g)].length;
39+
assert(list.length + risky > 0 && list.length <= 3,
40+
`Generated ${list.length} snapshots ` +
41+
`and ${risky} was too risky`);
4342
}

0 commit comments

Comments
 (0)