Conversation
internal/syncutil/registry.go's GetOrCreate had 91.7% coverage: the write-locked double-check branch (line 54-56, hit when a second goroutine loses the write-lock race but finds the key already populated) was only reachable probabilistically via the existing 64-goroutine stress test, and was not guaranteed to fire on every CI run. Add registry_internal_test.go (package syncutil, matching the existing ttl_cache_test.go whitebox pattern) with a deterministic test that holds registry.mu before starting two goroutines, releases it once both are blocked on the read lock, and coordinates the write-lock winner's create() call via channels so the loser is guaranteed to queue behind the write lock and hit the double-check on every run. This mirrors the analogous MapGetOrCreate double-check test already present in cache_test.go. Coverage: internal/syncutil 98.9% -> 100.0%; GetOrCreate 91.7% -> 100.0%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The synchronization does not guarantee both goroutines miss the initial lookup, so the target branch may remain uncovered.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds a white-box concurrency test intended to deterministically cover Registry.GetOrCreate’s double-check branch.
Changes:
- Adds coordinated concurrent
GetOrCreatecalls. - Verifies single creation and cached results.
| File | Description |
|---|---|
internal/syncutil/registry_internal_test.go |
Adds the concurrency test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| <-start | ||
| callStarted <- struct{}{} | ||
| v := registry.GetOrCreate("key", func() int { |
| func TestRegistryGetOrCreateDoubleCheckPreventsRedundantCreate(t *testing.T) { | ||
| registry := NewRegistry[string, int]() |
|
@copilot address review feedback |
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Addressed in 31f7118. The test now verifies both initial reads miss before releasing either worker into the write-locked double-check, uses bound testify asserters, and has timeout-safe cleanup. Repeated |
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE
No write succeeded on any surface. Independent evidence of mcpg's own write-blocking layer is covered by
|


File analyzed
internal/syncutil/registry_test.go/internal/syncutil/registry.goImprovement made
Registry.GetOrCreatehad 91.7% coverage: the write-locked double-check branch (lines 54-56 — hit when a goroutine loses the write-lock race but finds the key already populated by the winner) was only reachable probabilistically via the existing 64-goroutine stress test (TestRegistryGetOrCreateManyGoroutinesForcesDoubleCheck), so it wasn't guaranteed to fire on every CI run.Added
internal/syncutil/registry_internal_test.go(whiteboxpackage syncutil, matching the existingttl_cache_test.gopattern) withTestRegistryGetOrCreateDoubleCheckPreventsRedundantCreate, a deterministic test that:registry.mubefore starting two goroutines so both are guaranteed to block onmu.RLock().create()call on a channel so the loser is forced to queue behind the write lock, guaranteeing it hits the double-check on every run.This mirrors the analogous
MapGetOrCreatedouble-check test already present incache_test.go, reusing testify (assert/require) and timeout-guarded channel selects for stability (no flakiness across repeated-raceruns).The whitebox file is needed because
Registry.muis unexported — the externalsyncutil_testpackage (used by the other Registry tests) has no way to hold the lock deterministically.Coverage
internal/syncutilpackage: 98.9% → 100.0%Registry.GetOrCreate: 91.7% → 100.0%Test output
No existing tests were modified; all previously passing tests continue to pass.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
thishostdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.