Skip to content

add race test for concurrent event-type registry access#9

Merged
hstern merged 1 commit into
mainfrom
secevent-12-registry-concurrency
Jun 21, 2026
Merged

add race test for concurrent event-type registry access#9
hstern merged 1 commit into
mainfrom
secevent-12-registry-concurrency

Conversation

@hstern

@hstern hstern commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What

Adds a -race contention test for the package-level event-type registry, which is guarded by a sync.RWMutex: RegisterEventType writes under Lock, LookupEventType reads under RLock. The locking choice was previously asserted by construction but never exercised under concurrent load.

TestRegistryConcurrentAccess:

  • spawns 64 goroutines that concurrently register distinct event-type URIs (indexed per goroutine, so none triggers the legitimate duplicate-registration panic);
  • spawns 64 more that concurrently hammer LookupEventType and Events.Typed against those same URIs;
  • releases all of them together via a sync.WaitGroup start barrier to maximize reader/writer overlap;
  • after the writers join, asserts every registered URI resolves to its own working decoder that round-trips its payload and reports the matching EventTypeURI.

Under the suite's go test -race -shuffle=on this proves the RWMutex admits no data race between registrations and lookups, and that no concurrent write clobbered another's entry.

Scope

  • Test-only. No change to registry behavior or any other package semantics.
  • The duplicate-registration, empty-URI, and nil-decoder panic cases already have dedicated tests; this PR adds the concurrency proof those leave out — it does not duplicate them.
  • The fake event fixture stays unexported and shared in-test. No new public API and no importable test-helper subpackage.

Checks

  • gofmt -l . clean
  • go vet ./... clean
  • go mod tidy -diff no drift
  • go test -race -shuffle=on ./... green
  • golangci-lint run ./... — 0 issues

🤖 Generated with Claude Code

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>
@hstern hstern enabled auto-merge (squash) June 21, 2026 01:51
@hstern hstern merged commit cac5d88 into main Jun 21, 2026
4 checks passed
@hstern hstern deleted the secevent-12-registry-concurrency branch June 21, 2026 01:53
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