test: model registry and llminternal logging tests fail under go test -count=N
Required Information
Describe the Bug:
Two test groups pass on a single run but fail every time they are repeated with go test -count=N (N > 1). Both leave package-level state behind that the next run trips over. -count is the usual way to check for flakes, and CI only runs once, so this has gone unnoticed.
model/registry_test.go:TestNewLLMSingleMatch,TestRegisterDuplicatePatternPanics,TestNewLLMMultipleMatchesErrorandTestRegistryConcurrentAccesscallRegisteron the package-level registry and never remove their patterns. On the second run,Registerpanics because the pattern is already registered.internal/llminternal/base_flow_telemetry_test.go:TestLoggingSpanIDPropagationinstalls a freshLoggerProviderthroughglobal.SetLoggerProvideron every run. However,internal/telemetryresolvesotelLoggerfrom the global provider once, at package init, and the OTel global delegate only forwards to the first provider ever set. From the second run on, the records go to the first run's exporter and the test sees none.setupTestTracerin the same file already handles exactly this for the tracer with async.Once; the logger setup does not.
Steps to Reproduce:
go test ./model/ -count=2go test ./internal/llminternal/ -run '^TestLoggingSpanIDPropagation$' -count=2
Expected Behavior:
Both commands pass: each run is independent of the ones before it.
Observed Behavior:
panic: model: LLM pattern "^registry-test-ambiguous-.*$" is already registered [recovered, repanicked]
--- FAIL: TestNewLLMMultipleMatchesError (0.00s)
FAIL google.golang.org/adk/v2/model--- FAIL: TestLoggingSpanIDPropagation (0.00s)
base_flow_telemetry_test.go:347: expected 3 log records, got 0
FAIL google.golang.org/adk/v2/internal/llminternalA full go test -race -shuffle=on -count=3 ./... run shows these two as the only failures in the module.
Environment Details:
- ADK Library Version: v2.4.0 /
main@ 12f7cabc - OS: macOS (also reproducible on Linux; not OS-specific)
- Go Version: 1.26.6
Model Information:
- N/A (tests only)
Proposed fix (test-only, no production change)
model: add anisolateRegistry(t)helper that snapshots the registry and restores it int.Cleanup, and call it from the four tests above.llminternal: install the logger provider once with async.Once, likesetupTestTracer, and reset the shared in-memory exporter before and after each test.
I have both changes ready and will open a PR linked to this issue.
Source: google/adk-go