From 7ce82ad1de2556e12239934014ef8ea27a39cbb2 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Thu, 29 May 2025 13:10:11 +0530 Subject: [PATCH] test: account for truthy signal in flaky async_hooks tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the spawned child process gets closed with a signal, the exit code is not set and that is why the exit code assertion was failing. This change adjusts the test to check the signal and if it is truthy, it doesn't assert the exit code and instead logs the signal and continues the rest of the assertions. Refs: https://github.com/nodejs/node/issues/58463#issuecomment-2911460454 Refs: https://github.com/nodejs/node/issues/58199 Refs: https://github.com/nodejs/node/issues/58463 Signed-off-by: Darshan Sen PR-URL: https://github.com/nodejs/node/pull/58478 Reviewed-By: Gerhard Stöbich Reviewed-By: Chengzhong Wu Reviewed-By: Luigi Pinca --- test/async-hooks/test-emit-after-on-destroyed.js | 8 ++++++-- test/async-hooks/test-improper-unwind.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/async-hooks/test-emit-after-on-destroyed.js b/test/async-hooks/test-emit-after-on-destroyed.js index 1a10a1dfc74..5de296e6372 100644 --- a/test/async-hooks/test-emit-after-on-destroyed.js +++ b/test/async-hooks/test-emit-after-on-destroyed.js @@ -52,8 +52,12 @@ if (process.argv[2] === 'child') { child.stderr.on('data', (d) => { errData = Buffer.concat([ errData, d ]); }); child.stdout.on('data', (d) => { outData = Buffer.concat([ outData, d ]); }); - child.on('close', common.mustCall((code) => { - assert.strictEqual(code, 1); + child.on('close', common.mustCall((code, signal) => { + if (signal) { + console.log(`Child closed with signal: ${signal}`); + } else { + assert.strictEqual(code, 1); + } assert.match(outData.toString(), heartbeatMsg, 'did not crash until we reached offending line of code ' + `(found ${outData})`); diff --git a/test/async-hooks/test-improper-unwind.js b/test/async-hooks/test-improper-unwind.js index ea0eee025d7..de4ee1b758e 100644 --- a/test/async-hooks/test-improper-unwind.js +++ b/test/async-hooks/test-improper-unwind.js @@ -55,8 +55,12 @@ if (process.argv[2] === 'child') { child.stderr.on('data', (d) => { errData = Buffer.concat([ errData, d ]); }); child.stdout.on('data', (d) => { outData = Buffer.concat([ outData, d ]); }); - child.on('close', common.mustCall((code) => { - assert.strictEqual(code, 1); + child.on('close', common.mustCall((code, signal) => { + if (signal) { + console.log(`Child closed with signal: ${signal}`); + } else { + assert.strictEqual(code, 1); + } assert.match(outData.toString(), heartbeatMsg, 'did not crash until we reached offending line of code ' + `(found ${outData})`);