-
Notifications
You must be signed in to change notification settings - Fork 198
Flaky test: WorkloadFromContainerInfo hits real XDG filesystem #4341
Description
TestRuntimeStatusManager_GetWorkload/successful_get_workload intermittently fails with an EOF error in CI.
Root cause
WorkloadFromContainerInfo calls loadRunConfigFields, which internally creates a real state.LocalStore via state.LoadRunConfig → NewRunConfigStore(DefaultAppName). This hits the real XDG state directory (~/.local/state/toolhive/runconfigs/) instead of using dependency injection.
When tests run in parallel (especially with -race and -coverpkg=./...), a race condition can occur:
- Another test or process creates/truncates the runconfig file
store.Exists()returnstrue(file exists)json.Decodefails withEOFbecause the file is empty or partially written
This also affects fileStatusManager tests where mock GetReader returns a single-use io.NopCloser(strings.NewReader(...)) that gets consumed on the first read — now that WorkloadFromContainerInfo also reads from the store, subsequent reads return EOF.
Fix
- Add
state.Storeparameter toWorkloadFromContainerInfoandloadRunConfigFieldsfor proper dependency injection - Add
runConfigStorefield toruntimeStatusManager(matching the existing pattern infileStatusManager) - Update all callers to pass the injected store
- Fix test mocks to use
DoAndReturnfor fresh readers instead of single-useReturn(mockReader, ...)
Evidence
CI failure: https://github.com/stacklok/toolhive/actions/runs/23490251202/job/68356267110?pr=4335
status_test.go:122:
Error: Received unexpected error: EOF
Test: TestRuntimeStatusManager_GetWorkload/successful_get_workload
status_test.go:123:
Error: Not equal:
expected: "test-workload"
actual : ""