Repository navigation
[test-improver] Improve tests for syncutil MapGetOrCreate - #16817
Conversation
- Verify a failed create is retried on a later call instead of returning a stale failure. - Assert full cache contents in MultipleKeys rather than only the length. - Make RaceDetector check its returned errors and final cache state, so it asserts behavior instead of discarding results. - Replace the manual loop-variable copy and index loop with Go 1.22+ range forms. Coverage stays at 100% of statements; the change strengthens assertions. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are limited to strengthening retry, cache-content, and concurrency assertions in the test suite, with no active review issues identified.
No open issues 🎉
What changed in this PR
This PR strengthens the MapGetOrCreate test suite without changing production behavior by validating retry handling, complete cache contents, and concurrent results.
Changes:
- Verifies failed creations are retried and successful values are cached.
- Replaces length-only checks with full cache comparisons.
- Adds meaningful error and final-state assertions to the concurrent race test.
- Modernizes loop syntax and removes an unnecessary loop-variable copy.
| File | Description |
|---|---|
| internal/syncutil/cache_test.go | Strengthens MapGetOrCreate retry, cache-content, and concurrency test assertions. |
Review effort: Lite (adaptive)
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked on any tested surface. Gaps: (1) the gateway-backed
|
File analyzed
internal/syncutil/cache_test.go(implementation:internal/syncutil/cache.go)Improvements
DoesNotStoreOnErrornow verifies that a later call retriescreateand stores the successful value, not only that the failed value is absent.MultipleKeyscompares the full cache contents instead of onlylen.RaceDetectormade meaningful: it previously discarded every return value and asserted nothing. It now checks each goroutine's error and the final cache state, while still serving its-racepurpose.for i := 0; i < n; i++loops in favor ofrange.Coverage
100.0% of statements100.0% of statementsCoverage is unchanged because the package was already fully covered. This PR strengthens assertions rather than adding branches.
Verification
go test -v ./internal/syncutil/passes, including allMapGetOrCreatetests.go test -count=3 ./internal/syncutil/passes.go test -race -count=3 ./internal/syncutil/ -run MapGetOrCreatepasses.go vet ./internal/syncutil/andgofmt -lreport no issues.make agent-finished: format, build, lint-vet, and all Go unit and integration tests pass. The final Rust guard step fails in this sandbox because crates.io is unreachable (TLS certificate mismatch onindex.crates.io). It is unrelated to this change. golangci-lint was not installed, so it was not run.Warning
Firewall blocked 4 domains
The following domains were blocked by the firewall during workflow execution:
example.comnonexistent.localslow.example.comthishostdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.