From e691cd6bd9cac6ee8991a283d0e95115335fc2f5 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Sat, 11 Jan 2025 12:10:56 +0100 Subject: [PATCH] test_runner: integrate abort signal handling in test tree creation --- lib/internal/test_runner/harness.js | 5 ++++- lib/internal/test_runner/runner.js | 13 +------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index 36a7e1c21908e0..d51ea34d32f789 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -27,7 +27,7 @@ const { shouldColorizeTestFiles, } = require('internal/test_runner/utils'); const { queueMicrotask } = require('internal/process/task_queues'); -const { AbortController } = require('internal/abort_controller'); +const { AbortController, AbortSignal } = require('internal/abort_controller'); const { bigint: hrtime } = process.hrtime; const resolvedPromise = PromiseResolve(); const testResources = new SafeMap(); @@ -87,6 +87,9 @@ function createTestTree(rootTestOptions, globalOptions) { globalRoot = new Test({ __proto__: null, ...rootTestOptions, + signal: rootTestOptions.signal ? + AbortSignal.any([rootTestOptions.signal, harness.abortController.signal]) : + harness.abortController.signal, harness, name: '', }); diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 440c058d8282cc..7fc359f85b2d20 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -88,7 +88,6 @@ const { } = require('internal/test_runner/utils'); const { Glob } = require('internal/fs/glob'); const { once } = require('events'); -const { AbortSignal } = require('internal/abort_controller'); const { triggerUncaughtException, exitCodes: { kGenericUserError }, @@ -231,11 +230,6 @@ class FileTest extends Test { item.data.details.error = deserializeError(item.data.details.error); } if (item.type === 'test:bail') { - // <-- here we need to stop all the pending test files (aka subprocesses) - // To be replaced, just for poc - // this.root.harness.testsProcesses.forEach((child) => { - // child.kill(); - // }); this.root.harness.abortTestTree(); this.root.bailed = true; this.bailed = true; @@ -407,12 +401,7 @@ function runTestFile(path, filesWatcher, opts) { process.execPath, args, { __proto__: null, - signal: AbortSignal.any( - [ - t.signal, - opts.root.harness.abortController.signal, - ], - ), + signal: t.signal, encoding: 'utf8', env, stdio,