Skip to content

test(daemon): isolate HOME to fix flaky ~/.pilot test contention#252

Merged
TeoSlayer merged 1 commit into
mainfrom
fix/daemon-test-home-isolation
Jun 16, 2026
Merged

test(daemon): isolate HOME to fix flaky ~/.pilot test contention#252
TeoSlayer merged 1 commit into
mainfrom
fix/daemon-test-home-isolation

Conversation

@TeoSlayer

Copy link
Copy Markdown
Collaborator

Summary

Fixes a real, intermittent CI flake: pkg/daemon snapshot / 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 empty IdentityPath, so the
daemon resolves its on-disk state — ~/.pilot/managed_<netID>.json, the
hostname cache, the network snapshot — under os.UserHomeDir(), i.e. the
real home. Run in parallel (within the package and across the
packages go test ./... runs concurrently on one CI runner) these tests
read/write the same ~/.pilot files and race. It's timing-sensitive, so it
reddens macOS while ubuntu usually squeaks by.

Confirmed directly: before this change a test run leaves a stray
~/.pilot/managed_1.json in the real home.

Fix

Add a TestMain that points HOME (and USERPROFILE) at a throwaway dir
before any test runs, making the whole package hermetic. Tests that set
their own HOME via t.Setenv still work (override + restore relative to
the base).

Testing

  • go test -short ./pkg/daemon/ green; repeated concurrent ./pkg/...
    runs show no daemon-class failures.
  • Verified the real ~/.pilot is no longer written by the test run.

@TeoSlayer TeoSlayer requested a review from Alexgodoroja as a code owner June 15, 2026 18:09
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.
@TeoSlayer TeoSlayer force-pushed the fix/daemon-test-home-isolation branch from 43d1413 to 19e8a67 Compare June 16, 2026 07:36
@TeoSlayer TeoSlayer merged commit 53358fe into main Jun 16, 2026
7 of 8 checks passed
@TeoSlayer TeoSlayer deleted the fix/daemon-test-home-isolation branch June 16, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants