Skip to content

Fix global registry test panics with -count>1#439

Open
klowdo wants to merge 2 commits intomainfrom
fix/global-registry-test-panic
Open

Fix global registry test panics with -count>1#439
klowdo wants to merge 2 commits intomainfrom
fix/global-registry-test-panic

Conversation

@klowdo
Copy link
Copy Markdown
Collaborator

@klowdo klowdo commented Mar 4, 2026

Description

Running go test -count=20 panics because test functions register types into global registries without cleanup. On the second iteration the registry rejects duplicates with a panic.

Affected Components

  • Aggregate registry
  • Command registry
  • Event data registry
  • Context marshaler/unmarshaler registries

Related Issues

None

Solution and Design

  • Add UnregisterAggregate following the existing pattern of UnregisterCommand and UnregisterEventData
  • Add defer cleanup in tests that register into global registries (aggregate_test.go, command_test.go, event_test.go)
  • For context marshalers/unmarshalers (append-only slices with no unregister API), save and restore slice length via defer
  • Make TestCopyContext self-contained instead of relying on side effects from prior tests

Steps to test and verify

  1. go test -race -count=20 . — all iterations pass without panics

klowdo added 2 commits March 4, 2026 11:29
Follows the existing pattern of UnregisterCommand and UnregisterEventData
to allow removing aggregate type registrations from the global registry.
Tests that register types into global registries now defer cleanup,
preventing duplicate-registration panics on subsequent test iterations.
Context marshaler/unmarshaler tests save and restore slice lengths.
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 53.105% (+0.002%) from 53.103%
when pulling 78cb7b8 on fix/global-registry-test-panic
into 335f072 on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants