#1656·adk-go

test: model registry and llminternal logging tests fail under go test -count=N

Author: Vivek1106-04Created Sep 28, 2026Updated Sep 28, 2026

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.

  1. model/registry_test.go: TestNewLLMSingleMatch, TestRegisterDuplicatePatternPanics, TestNewLLMMultipleMatchesError and TestRegistryConcurrentAccess call Register on the package-level registry and never remove their patterns. On the second run, Register panics because the pattern is already registered.

  2. internal/llminternal/base_flow_telemetry_test.go: TestLoggingSpanIDPropagation installs a fresh LoggerProvider through global.SetLoggerProvider on every run. However, internal/telemetry resolves otelLogger from 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. setupTestTracer in the same file already handles exactly this for the tracer with a sync.Once; the logger setup does not.

Steps to Reproduce:

  1. go test ./model/ -count=2
  2. go 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/llminternal

A 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 an isolateRegistry(t) helper that snapshots the registry and restores it in t.Cleanup, and call it from the four tests above.
  • llminternal: install the logger provider once with a sync.Once, like setupTestTracer, 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.