test: fix update-check TempDir race + ws Start_GracefulShutdown poll#72
Merged
Conversation
Two flake reductions surfaced by the 2026-06-11 test audit, bundled
because they share the same shape — replace a sleep / a leaky goroutine
with a deterministic wait.
- TestCheckForModelUpdates_UpdateCheckDisabledInConfig (+ sibling
ValidConfig_NoUpdateCheck): DefaultConfig now has update_check=true,
so even tests that "expect early return" fall through and start the
background poll goroutine. That goroutine writes
<HOME>/.nxd/update-status.json AFTER the test returns, racing
t.TempDir's cleanup. Repro in CI shows up as `unlinkat … directory
not empty` under -race. Hard-disable the poll with
t.Setenv("NXD_UPDATE_CHECK", "false") — the function returns at
line 70 of root.go before any goroutine spawns.
- TestServer_Start_GracefulShutdown used a flat 200ms sleep to wait for
the listener to bind. Replace with a 10ms poll loop on s.BindAddr()
with a 2s deadline. Three repeated runs now complete in ~20ms each
(vs 200ms before) and there's no hard-coded wait to drift into flake
on slow CI runners.
Couldn't use the existing waitForPort helper because the test sets
s.port = 0 (let the OS pick).
Surfaced by 2026-06-11 test audit (TEST-P2-2, plus task #7 update-check
flake).
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.
Summary
Two flake reductions surfaced by the 2026-06-11 test audit, bundled because they share the same shape — replace a sleep / a leaky goroutine with a deterministic wait.
TestCheckForModelUpdates_UpdateCheckDisabledInConfig(+ siblingValidConfig_NoUpdateCheck):DefaultConfignow hasupdate_check=true, so even tests that "expect early return" fall through and start the background poll goroutine. That goroutine writes<HOME>/.nxd/update-status.jsonAFTER the test returns, racingt.TempDir's cleanup. Repro in CI:unlinkat … directory not emptyunder-race. Fix: hard-disable witht.Setenv("NXD_UPDATE_CHECK", "false")— the function returns at root.go:70 before any goroutine spawns.TestServer_Start_GracefulShutdownused a flat 200 ms sleep to wait for bind. Replace with a 10 ms poll ons.BindAddr()capped at 2 s. Three repeated runs now complete in ~20 ms each (vs 200 ms before).Test plan
TestCheckForModelUpdates_*× 5 reruns clean locally under-race.TestServer_Start_GracefulShutdown× 3 reruns: each ~20 ms.go build ./...,go vet ./...,go test ./... -count=1 -timeout 240sall green.Audit traceability
Test audit TEST-P2-2 + task #7 (update-check flake).