Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

tests: a decoder test counts its cheapest read, so another goroutine's allocations don't fail it (#3283)

yetoneba1dc7f97566
diff --git a/internal/sessions/packed_decoder_test.go b/internal/sessions/packed_decoder_test.go
index feee97f27..f7d642136 100644
--- a/internal/sessions/packed_decoder_test.go
+++ b/internal/sessions/packed_decoder_test.go
@@ -108,17 +108,21 @@ func dshPacked(t testing.TB, dir string, size int) (string, int64) {
return p, last
}
-// allocated is the bytes fn allocates a call, on average over n calls
-// after a first one.
+// allocated is the bytes fn allocates a call, the least of n calls after
+// a first one. TotalAlloc counts every goroutine in the process, so
+// another test's leftover work lands on whichever call it overlaps; a
+// decoder made anew lands on every call, and the least still shows it.
func allocated(n int, fn func()) uint64 {
fn()
- var a, b runtime.MemStats
- runtime.ReadMemStats(&a)
+ least := ^uint64(0)
for i := 0; i < n; i++ {
+ var a, b runtime.MemStats
+ runtime.ReadMemStats(&a)
fn()
+ runtime.ReadMemStats(&b)
+ least = min(least, b.TotalAlloc-a.TotalAlloc)
}
- runtime.ReadMemStats(&b)
- return (b.TotalAlloc - a.TotalAlloc) / uint64(n)
+ return least
}
func scanPacked(t testing.TB, p string) int {