add race test for concurrent event-type registry access#9
Merged
Conversation
The event-type registry (RegisterEventType / LookupEventType) is a process-wide map guarded by a sync.RWMutex so that the read-heavy lookup path runs in parallel while the rare registration writes serialize. That locking choice was asserted by construction but never exercised under contention. Add TestRegistryConcurrentAccess: 64 goroutines concurrently register distinct event-type URIs while 64 more hammer LookupEventType and Events.Typed against those URIs, all released together by a WaitGroup start barrier to maximize reader/writer overlap. Under the suite's go test -race -shuffle=on it proves the RWMutex admits no data race between registrations and lookups; after the writers join, it confirms every registered URI resolves to its own working decoder, so no concurrent write clobbered another. Test-only. The duplicate-registration, empty-URI, and nil-decoder panic cases already have dedicated tests; this adds the concurrency proof those leave out. The fake event fixture stays unexported and shared in-test — no new public API or importable test helper. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
-racecontention test for the package-level event-type registry, which is guarded by async.RWMutex:RegisterEventTypewrites underLock,LookupEventTypereads underRLock. The locking choice was previously asserted by construction but never exercised under concurrent load.TestRegistryConcurrentAccess:LookupEventTypeandEvents.Typedagainst those same URIs;sync.WaitGroupstart barrier to maximize reader/writer overlap;EventTypeURI.Under the suite's
go test -race -shuffle=onthis proves theRWMutexadmits no data race between registrations and lookups, and that no concurrent write clobbered another's entry.Scope
Checks
gofmt -l .cleango vet ./...cleango mod tidy -diffno driftgo test -race -shuffle=on ./...greengolangci-lint run ./...— 0 issues🤖 Generated with Claude Code