-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
test: fix dangling promise in test_runner no isolation test setup #57595
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: fix dangling promise in test_runner no isolation test setup #57595
Conversation
Review requested:
|
The test is passing on the before(): global
before one: <root>
suite one
before two: <root>
suite two
- beforeEach(): global
beforeEach one: suite one - test
beforeEach two: suite one - test
suite one - test
- afterEach(): global
afterEach one: suite one - test
afterEach two: suite one - test
before suite two: suite two
- beforeEach(): global
beforeEach one: suite two - test
beforeEach two: suite two - test
suite two - test
- afterEach(): global
afterEach one: suite two - test
afterEach two: suite two - test
- after(): global
after one: <root>
after two: <root> @avivkeller and I did some digging, and they've summarised our findings over here (but let's keep the discussion of it to this PR) #57419 (comment). |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57595 +/- ##
=======================================
Coverage 90.24% 90.25%
=======================================
Files 630 630
Lines 185129 185074 -55
Branches 36238 36220 -18
=======================================
- Hits 167064 167030 -34
+ Misses 11045 11024 -21
Partials 7020 7020 🚀 New features to boost your workflow:
|
@@ -1,6 +0,0 @@ | |||
import('node:test').then((test) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add tests for both require and import in cjs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already in this PR, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing it but where is there a cjs test with import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OH, sorry I think I misunderstood. You want
node --import global.cjs test.js
node --require global.cjs test.js // this exists
node --import global.mjs test.js // this exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (and the import CJS case passes): 6a38d32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MoLow 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JakobJingleheimer if nobody precedes me, I'll take a look ASAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmarchini looks like nobody is, so if you could, that would be great 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests seem to need an adjustment, but implementation LGTM
@MoLow hmm? could you advise what about the test needs adjusting? After fixing the dangling promise issue, it looks good to me 🤔 Since it affects only the |
@JakobJingleheimer I was referring to the failing tests, not necessarily related to this change |
cc @JakobJingleheimer as per our discussion. I checked and, unless I completely missed something, the cause is the following: Because of the node/lib/internal/process/pre_execution.js Line 670 in 3db5491
This executes the before hook but no other hooks.At this point, the test runner (due to the --test flag) creates a new root test, which, however, does not handle the --require flag.For this reason, the behaviour is what we’re seeing. Sure! Here's just the part you asked for: Here's an example output with some added logs:
|
Awesome! Thank you @pmarchini 🙏 In that case, this is an outstanding bug in the implementation, which I think is outside the scope of this PR and the others that are affected (blocked) by it. Since it's a bug that already exists and was discovered by fixing a test, I think it's acceptable to mark the failing test-case as an expected failure, and fix that subsequently. Thoughts @MoLow @pmarchini? |
@JakobJingleheimer +1 on my side, I'd suggest adding a todo comment about the root cause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Landed in 5a2614f |
PR-URL: nodejs#57595 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
PR-URL: #57595 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
PR-URL: #57595 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
PR-URL: #57595 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
PR-URL: #57595 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
The
--import
ed /--require
d file contained an un-await
ed dynamic import, so it's subsequent code was not guaranteed to finish before the entry-point starts. Strangely that should have caused this test to fail some times, but it seems to be consistently fast enough so that the race condition doesn't occur.I checked with the original author of the test, and this was not intended (it was only done that way in an attempt to simplify setup and recycle fixtures).
However, after speed improvements in #57419, the race condition was exposed and does occur consistently (causing the global hooks to get registered out of their intended/expected sequence).