Skip to content

Flaky test: WorkloadFromContainerInfo hits real XDG filesystem #4341

@JAORMX

Description

@JAORMX

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.LoadRunConfigNewRunConfigStore(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:

  1. Another test or process creates/truncates the runconfig file
  2. store.Exists() returns true (file exists)
  3. json.Decode fails with EOF because 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.Store parameter to WorkloadFromContainerInfo and loadRunConfigFields for proper dependency injection
  • Add runConfigStore field to runtimeStatusManager (matching the existing pattern in fileStatusManager)
  • Update all callers to pass the injected store
  • Fix test mocks to use DoAndReturn for fresh readers instead of single-use Return(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  : ""

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggoPull requests that update go code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions