Skip to content

fix(storage): remove t.Parallel() from tests that mutate shared state#76

Merged
platinummonkey merged 1 commit intomainfrom
fix/storage-test-parallel-race
Feb 17, 2026
Merged

fix(storage): remove t.Parallel() from tests that mutate shared state#76
platinummonkey merged 1 commit intomainfrom
fix/storage-test-parallel-race

Conversation

@platinummonkey
Copy link
Collaborator

Summary

Fixes a flaky CI failure (TestDetectBackend_InvalidEnvValue panic) caused by parallel tests racing on shared global state — the singleton storage cache and the DD_TOKEN_STORAGE environment variable.

Changes

  • Remove t.Parallel() from all factory tests that call ResetStorage() or modify env vars (pkg/auth/storage/factory_test.go)
  • Replace manual os.Setenv/defer os.Unsetenv with t.Setenv() for automatic cleanup and parallel-safety enforcement
  • Change t.Errort.Fatal where execution must stop on nil error to prevent nil pointer dereferences

Root Cause

All tests in factory_test.go were marked t.Parallel() but they all mutate the same global state:

  1. ResetStorage() clears the singleton cache
  2. os.Setenv(StorageEnvVar, ...) modifies a process-wide env var

When TestDetectBackend_InvalidEnvValue ran concurrently with other tests, another test could populate the cache or clear the env var before GetStorage(nil) was called, causing it to succeed instead of returning an error. The subsequent err.Error() call on nil then panicked.

Test plan

  • go test ./pkg/auth/storage/ -v -race -count=1 passes
  • Full suite go test ./... -count=1 passes
  • Race detector confirms no data races

🤖 Generated with Claude Code

The factory_test.go tests all mutate shared global state — the singleton
storage cache via ResetStorage()/GetStorage() and the DD_TOKEN_STORAGE
env var via os.Setenv(). Running them concurrently caused a race where
one test's cache reset or env var change was visible to another,
producing flaky failures (nil error → nil pointer dereference on
err.Error()).

- Remove t.Parallel() from all tests that touch global storage state
- Replace manual os.Setenv/defer os.Unsetenv with t.Setenv for
  automatic cleanup and parallel-safety enforcement
- Change t.Error to t.Fatal where execution must stop on nil error
  to prevent nil pointer dereferences

Fixes CI flake: TestDetectBackend_InvalidEnvValue panic in headless
environments where keychain is unavailable.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@platinummonkey platinummonkey requested a review from a team as a code owner February 17, 2026 23:39
@platinummonkey platinummonkey merged commit 8fe8ed8 into main Feb 17, 2026
5 checks passed
@platinummonkey platinummonkey deleted the fix/storage-test-parallel-race branch February 17, 2026 23:41
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.

1 participant

Comments