From d5d56ec3d4943a2224386b19e099626284f0b8b8 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 27 Dec 2020 09:44:19 -0800 Subject: [PATCH] test: add test for reused AbortController with execfile() Test that reusing an aborted AbortController with execfile() results in immediate SIGTERM. PR-URL: https://github.com/nodejs/node/pull/36644 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Daijiro Wachi --- test/parallel/test-child-process-execfile.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-child-process-execfile.js b/test/parallel/test-child-process-execfile.js index aec80b4e2baf22..1788b733934add 100644 --- a/test/parallel/test-child-process-execfile.js +++ b/test/parallel/test-child-process-execfile.js @@ -53,11 +53,24 @@ const execOpts = { encoding: 'utf8', shell: true }; const ac = new AbortController(); const { signal } = ac; - const callback = common.mustCall((err) => { + const firstCheck = common.mustCall((err) => { assert.strictEqual(err.code, 'ABORT_ERR'); assert.strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.signal, undefined); + }); + + const secondCheck = common.mustCall((err) => { + assert.strictEqual(err.code, null); + assert.strictEqual(err.name, 'Error'); + assert.strictEqual(err.signal, 'SIGTERM'); }); - execFile(process.execPath, [echoFixture, 0], { signal }, callback); + + execFile(process.execPath, [echoFixture, 0], { signal }, (err) => { + firstCheck(err); + // Test that re-using the aborted signal results in immediate SIGTERM. + execFile(process.execPath, [echoFixture, 0], { signal }, secondCheck); + }); + ac.abort(); }