From 9f61cbd1fdc4d439071ffc60973cf07e2403d8b3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 16 Mar 2021 03:44:04 +0800 Subject: [PATCH] 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 Reviewed-By: Rich Trott --- ...test-heapsnapshot-near-heap-limit-worker.js | 17 ++++++++++------- .../test-heapsnapshot-near-heap-limit.js | 18 ++++++++++++++---- .../test-heapsnapshot-near-heap-limit-big.js | 11 +++++------ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/test/parallel/test-heapsnapshot-near-heap-limit-worker.js b/test/parallel/test-heapsnapshot-near-heap-limit-worker.js index edbe2f6c617505..48845bdad00a48 100644 --- a/test/parallel/test-heapsnapshot-near-heap-limit-worker.js +++ b/test/parallel/test-heapsnapshot-near-heap-limit-worker.js @@ -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); + } } diff --git a/test/parallel/test-heapsnapshot-near-heap-limit.js b/test/parallel/test-heapsnapshot-near-heap-limit.js index 42b66871d429c2..92e06cb25e44e4 100644 --- a/test/parallel/test-heapsnapshot-near-heap-limit.js +++ b/test/parallel/test-heapsnapshot-near-heap-limit.js @@ -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`); } diff --git a/test/pummel/test-heapsnapshot-near-heap-limit-big.js b/test/pummel/test-heapsnapshot-near-heap-limit-big.js index f70d562c1d1ee4..3442ae068be06f 100644 --- a/test/pummel/test-heapsnapshot-near-heap-limit-big.js +++ b/test/pummel/test-heapsnapshot-near-heap-limit-big.js @@ -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`); }