test_runner: drain event loop before force-exit process.exit() - #64857
Open
NeverBetterEnough wants to merge 1 commit into
Open
test_runner: drain event loop before force-exit process.exit()#64857NeverBetterEnough wants to merge 1 commit into
NeverBetterEnough wants to merge 1 commit into
Conversation
When --test-force-exit is used with --test-concurrency > 1, the parent process can silently lose test verdicts from child processes. This happens because process.exit() fires immediately after reporter destinations close, before the event loop has a chance to drain pending write operations on child-process report streams. The previous fix (nodejs#55099) ensured reporter destination files are flushed before exit, but did not extend the flush guarantee to the child-to-parent report stream layer. With process isolation and concurrency, V8-serialized test-event frames from children can be truncated or dropped. Add a setImmediate tick before process.exit() to allow the event loop to drain any remaining write operations on reporter destinations (including child-process stdout pipes). Fixes: nodejs#64833
Collaborator
|
Review requested:
|
Member
|
@NeverBetterEnough Please sign your commit by adding a |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64857 +/- ##
==========================================
- Coverage 90.16% 90.15% -0.01%
==========================================
Files 746 746
Lines 242760 242766 +6
Branches 45765 45757 -8
==========================================
- Hits 218875 218863 -12
- Misses 15375 15402 +27
+ Partials 8510 8501 -9
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
--test-force-exitis used with--test-concurrency > 1, the parent process can silently lose test verdicts from child processes. This happens becauseprocess.exit()fires immediately after reporter destinations close, before the event loop has a chance to drain pending write operations on child-process report streams.The previous fix (#55099) ensured reporter destination files are flushed before exit, but did not extend the flush guarantee to the child-to-parent report stream layer. With process isolation and concurrency, V8-serialized test-event frames from children can be truncated or dropped before the parent's FileTest parser consumes them.
This change adds a
setImmediatetick beforeprocess.exit()to allow the event loop one full iteration to drain any remaining write operations on reporter destinations (including child-process stdout pipes).Changes
lib/internal/test_runner/test.js: Addedawait new Promise((resolve) => setImmediate(resolve))beforeprocess.exit()in the force-exit handlertest/parallel/test-runner-force-exit-concurrency.mjs: New regression test (8 files × 10 tests, run 5 times to catch the race)Reproduction
The issue requires
--test-force-exit+--test-concurrency > 1(process isolation). With many fast test files, the parent silently loses a fraction of test verdicts — both built-in and custom reporters receive fewer events than tests that actually ran, yet the run still exits 0.Impact
Silent partial results defeat the purpose of a test run. On a production suite (Node v24.18.0, 1351 tests), the parent reported as few as 1168. CI stays green while a meaningful fraction of the suite is unaccounted for.
Fixes: #64833
Refs: #54327, #55099