Skip to content

test: reduce flakiness of test-runner-output.mjs - #52146

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
cjihrig:flake
Mar 19, 2024
Merged

test: reduce flakiness of test-runner-output.mjs#52146
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
cjihrig:flake

Conversation

@cjihrig

@cjihrig cjihrig commented Mar 18, 2024

Copy link
Copy Markdown
Contributor

This commit is similar to #51952. When the system is under load it is possible for these timeout tests to become flaky. We work around that by using a much longer setTimeout() in the test so that it is not racing against the test's timeout. But, we have to unref() such a large timeout. And, because test timeouts do not currently keep the event loop alive, we use a different setTimeout() for that purpose.

Fixes: #52139
Refs: #52140

This commit is similar to nodejs#51952. When the system is under load
it is possible for these timeout tests to become flaky. We
work around that by using a much longer setTimeout() in the test
so that it is not racing against the test's timeout. But, we have
to unref() such a large timeout. And, because test timeouts do
not currently keep the event loop alive, we use a different
setTimeout() for that purpose.

Fixes: nodejs#52139
Refs: nodejs#52140
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure. labels Mar 18, 2024
@aduh95 aduh95 added fast-track PRs proposed for a shorter-than-standard waiting period before landing. author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. labels Mar 18, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Fast-track has been requested by @aduh95. Please 👍 to approve.

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 18, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@MoLow MoLow added the commit-queue PRs queued for automated landing through the Commit Queue. label Mar 19, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Mar 19, 2024
@nodejs-github-bot
nodejs-github-bot merged commit 978d5a2 into nodejs:main Mar 19, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 978d5a2

@cjihrig
cjihrig deleted the flake branch March 19, 2024 13:19
marco-ippolito pushed a commit that referenced this pull request May 2, 2024
This commit is similar to #51952. When the system is under load
it is possible for these timeout tests to become flaky. We
work around that by using a much longer setTimeout() in the test
so that it is not racing against the test's timeout. But, we have
to unref() such a large timeout. And, because test timeouts do
not currently keep the event loop alive, we use a different
setTimeout() for that purpose.

Fixes: #52139
Refs: #52140
PR-URL: #52146
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
marco-ippolito pushed a commit that referenced this pull request May 3, 2024
This commit is similar to #51952. When the system is under load
it is possible for these timeout tests to become flaky. We
work around that by using a much longer setTimeout() in the test
so that it is not racing against the test's timeout. But, we have
to unref() such a large timeout. And, because test timeouts do
not currently keep the event loop alive, we use a different
setTimeout() for that purpose.

Fixes: #52139
Refs: #52140
PR-URL: #52146
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
tnunamak added a commit to PDP-Connect/data-connect that referenced this pull request Sep 3, 2026
…r (Node test-runner false positive)

Root-caused the largest remaining failure cluster (55 of 62 failures at last
measurement, spanning 5 files): a documented, known Node.js test-runner limitation,
not a bug in this repo's production code.

nodejs/node#51381 ("spurious 'Promise resolution is still pending' when a callback
test fails") and its follow-up discussion in nodejs/node#52025 describe the exact
mechanism: the test runner uses an unref()'d internal timer for its own timeout
bookkeeping. When test code ALSO uses an unref()'d timer racing against a
deliberately-still-pending promise -- a completely valid, common pattern (e.g. "assert
that operation A times out while operation B is left deliberately in-flight, to prove
cancelling A doesn't affect B") -- the runner can flag that still-pending promise as
abandoned before the real race actually resolves, well before either the test's own
assertions or its explicit timeout value would suggest. Confirmed directly: shortening
one such test's internal deadline by 20x still failed at the same speed, ruling out
"the wait is too long" as the cause.

Node's own core test suite documents the accepted workaround for this exact
interaction (see the discussion linked above and nodejs/node#52146): a separate,
ref()'d "keep the event loop alive" timer for the test's duration, cleared in
t.after(), independent of whatever unref()'d timer the code under test uses. Applied
this to the 5 affected files, in each file's existing shared per-test setup helper
(freshDb()/setup()) where one exists, so every test in the file gets the same
protection rather than patching call sites one at a time.

Verified per-file in isolation (node --import tsx --test test/<file>.test.ts), each
now fully green: controller-cancel-run.test.ts 5/5 (was 1/5), controller-browser-
surface-leases.test.ts 39/39 (was 28/39), controller-phantom-active-run.test.ts 18/18
+ 3 legitimately-skipped Postgres tests (was all 21 failing), run-generation-
fencing.test.ts 5/5 (was 1/5), source-declaration-trust.test.ts 19/19 (was 5/19,
after also fixing a second instance of the same shape in the same file -- "declaration
retrieval bounds DNS work by the configured deadline" -- found once the first fix
unblocked the rest of the file's cascade).

Full suite dropped from 62 to 16 failures with zero regressions (confirmed via a
before/after diff of the exact failing-test-name set). The remaining 16 are unrelated,
already-tracked items (data-connect#53, data-connectors#67, the deliberately-deferred
Signal connector rollout, and 2 pre-existing scanner findings) -- EXCEPT a handful of
tests in source-declaration-trust.test.ts that still show this same failure signature
specifically under the full suite's concurrent-worker execution model, despite passing
100% when that file runs standalone. Not yet root-caused whether this is a
concurrency-specific variant of the same Node limitation or a separate interaction;
noted for follow-up rather than blocking this fix, which is unambiguously a large net
improvement either way.

Assisted-by: AI
Signed-off-by: Tim Nunamaker <tnunamak@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. fast-track PRs proposed for a shorter-than-standard waiting period before landing. needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky: test-runner-output

4 participants