Skip to content

test(server): close race in MockProvider mock-message access#98

Draft
miotte wants to merge 1 commit into
mainfrom
miotte-pr5
Draft

test(server): close race in MockProvider mock-message access#98
miotte wants to merge 1 commit into
mainfrom
miotte-pr5

Conversation

@miotte
Copy link
Copy Markdown
Contributor

@miotte miotte commented May 22, 2026

Fixes #96

Summary

  • Encapsulate MockProvider.MockMessages behind a sync.Mutex with SetMockMessages and takeMockMessages helpers.
  • Drop the in-Subscribe reassignment in favor of take semantics, so a Subscribe goroutine that outlives its test can no longer race the next test's setup.

Test plan

  • go test ./internal/server/... -race -count=10

The package-level mockp is shared across tests, and Subscribe runs in a
goroutine that defers a 500ms sleep before returning. That goroutine can
outlive the test that triggered it, so its read/reset of MockMessages
races against the next test's Subscribe goroutine when -race is enabled.

Encapsulate the slice behind a sync.Mutex with SetMockMessages and
takeMockMessages helpers, and drop the in-Subscribe reassignment in favor
of the take semantics.

Signed-off-by: Michael Otteni <MichaelGOtteni@gmail.com>
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.

Race in MockProvider mock-message access across overlapping Subscribe goroutines

1 participant