Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: call abort on test finish #48827

Merged
merged 12 commits into from
Jul 21, 2023

Conversation

rluvaton
Copy link
Member

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jul 18, 2023

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jul 18, 2023
@rluvaton rluvaton marked this pull request as ready for review July 18, 2023 14:24
Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, let's make sure to run benchmarks before landing because we recreate the controller each time now

MoLow
MoLow previously requested changes Jul 18, 2023
Copy link
Member

@MoLow MoLow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to avoid recreation of the controller by testing for this.parent, wich is the case of hooks and the root test:

diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js
index cc56eec948..b81fc80bbf 100644
--- a/lib/internal/test_runner/test.js
+++ b/lib/internal/test_runner/test.js
@@ -586,13 +586,17 @@ class Test extends AsyncResource {
         return;
       }
 
-      this.#abortController.abort();
 
+      if (this.parent !== null) {
+        this.#abortController.abort();
+      }
       await afterEach();
       await after();
       this.pass();
     } catch (err) {
-      this.#abortController.abort();
+      if (this.parent !== null) {
+        this.#abortController.abort();
+      }
       try { await afterEach(); } catch { /* test is already failing, let's ignore the error */ }
       try { await after(); } catch { /* Ignore error. */ }
       if (isTestFailureError(err)) {
@@ -747,10 +751,6 @@ class Test extends AsyncResource {
     this.reporter.start(this.nesting, kFilename, this.name);
   }
 
-  recreateAbortController() {
-    this.#abortController = new AbortController();
-    this.signal = this.#abortController.signal;
-  }
 }
 
 class TestHook extends Test {
@@ -773,8 +773,6 @@ class TestHook extends Test {
     return true;
   }
   postRun() {
-    // Need to recreate the abort controller because we abort each time in the end
-    super.recreateAbortController();
   }
 }

@MoLow MoLow dismissed their stale review July 18, 2023 15:38

requested changes addressed

Copy link
Member

@MoLow MoLow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dismissed changes request, but I would still prefer if the abort is done after hooks run

@benjamingr
Copy link
Member

dismissed changes request, but I would still prefer if the abort is done after hooks run

@rluvaton let's do that?

@rluvaton
Copy link
Member Author

fixed

@@ -0,0 +1,19 @@
module.exports = {
waitForAbort: function ({ testNumber, signal }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not await Promise.race(once(signal, 'abort'), setTimeout(1000)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we wait for the afterEach in the test runner...

await afterEach();
await after();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so doing await will always fail...

Co-authored-by: Moshe Atlow <moshe@atlow.co.il>
@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 20, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 20, 2023
@nodejs-github-bot nodejs-github-bot merged commit 24c3d8a into nodejs:main Jul 21, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 24c3d8a

@rluvaton
Copy link
Member Author

This need to be backported, right?

@atlowChemi
Copy link
Member

This need to be backported, right?

I can backport to v20 at the beginning of next week 🙂

@rluvaton rluvaton deleted the call-abort-on-test-finish branch July 21, 2023 13:06
@aduh95
Copy link
Contributor

aduh95 commented Jul 21, 2023

This shouldn't need any manual backport, or am I missing something?

@rluvaton
Copy link
Member Author

I actually don't really know 😅

@MoLow
Copy link
Member

MoLow commented Jul 22, 2023

Backporting is only needed when there is a git conflict, or if tests break or some other reason like that

rluvaton added a commit to rluvaton/node that referenced this pull request Jul 24, 2023
PR-URL: nodejs#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
pluris pushed a commit to pluris/node that referenced this pull request Aug 6, 2023
PR-URL: nodejs#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
pluris pushed a commit to pluris/node that referenced this pull request Aug 7, 2023
PR-URL: nodejs#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
RafaelGSS pushed a commit that referenced this pull request Aug 15, 2023
PR-URL: #48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
targos pushed a commit that referenced this pull request Oct 28, 2023
PR-URL: #48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test runner executes after() in declared order
6 participants