test(daemon): isolate HOME to fix flaky ~/.pilot test contention#252
Merged
Conversation
Many pkg/daemon tests construct New(Config{}) with an empty IdentityPath,
so the daemon resolves managed-engine state (~/.pilot/managed_<netID>.json),
the hostname cache, and the network snapshot under os.UserHomeDir() — the
real home. Run in parallel (within the package and across the packages
go test ./... runs concurrently on a shared CI runner) those tests race on
the same ~/.pilot files, flaking on macOS (the snapshot / hostname-cache /
managed-engine tests, which pass in isolation).
Add a TestMain that points HOME (and USERPROFILE) at a throwaway dir before
any test runs, making the package hermetic. Verified: tests no longer touch
the real ~/.pilot; suite green; repeated concurrent ./pkg/... runs clean.
43d1413 to
19e8a67
Compare
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
Fixes a real, intermittent CI flake:
pkg/daemonsnapshot / hostname-cache/ managed-engine tests fail on macOS runs (and locally under load) while
passing in isolation.
Root cause
Many tests here build
New(Config{})with an emptyIdentityPath, so thedaemon resolves its on-disk state —
~/.pilot/managed_<netID>.json, thehostname cache, the network snapshot — under
os.UserHomeDir(), i.e. thereal home. Run in parallel (within the package and across the
packages
go test ./...runs concurrently on one CI runner) these testsread/write the same
~/.pilotfiles and race. It's timing-sensitive, so itreddens macOS while ubuntu usually squeaks by.
Confirmed directly: before this change a test run leaves a stray
~/.pilot/managed_1.jsonin the real home.Fix
Add a
TestMainthat pointsHOME(andUSERPROFILE) at a throwaway dirbefore any test runs, making the whole package hermetic. Tests that set
their own
HOMEviat.Setenvstill work (override + restore relative tothe base).
Testing
go test -short ./pkg/daemon/green; repeated concurrent./pkg/...runs show no daemon-class failures.
~/.pilotis no longer written by the test run.