Commit 1214693
fix(op-batcher): fix flaky TestChannelManager_Memory (#19579)
* fix(op-batcher): fix flaky TestChannelManager_Memory by using TotalAlloc
The test measured memory using `runtime.MemStats.Alloc` (current heap
size), which can decrease after GC runs. The subtraction
`finalMem.Alloc - initialMem.Alloc` on uint64 values underflows when
GC reclaims enough memory between the two reads, producing a massive
number that exceeds the 512MB threshold.
Switch to `TotalAlloc` which is monotonically increasing and safe to
subtract. Raise the threshold to 1GB since TotalAlloc counts cumulative
allocations including freed memory. Actual usage is ~30MB, so the
threshold provides ample headroom.
Flake count: 19 in CircleCI (go-tests-short).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(op-batcher): use HeapInuse absolute threshold for TestChannelManager_Memory
Address review feedback: use HeapInuse after GC as absolute threshold
instead of TotalAlloc delta. This correctly measures retained memory
(catching leaks) while eliminating the uint64 underflow that caused
flakiness.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(op-batcher): guard against uint64 underflow in TestChannelManager_Memory
The test measures retained memory by subtracting initial Alloc from final
Alloc. When GC reclaims memory between the two ReadMemStats calls (from
other goroutines), final Alloc can be less than initial Alloc, causing a
uint64 underflow that produces a massive value and fails the 512MB check.
Guard the subtraction: if final < initial, treat the delta as zero. This
preserves the original test semantics (bounding retained heap) while
handling the GC timing edge case that causes intermittent failures.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 3732655 commit 1214693
1 file changed
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
146 | 152 | | |
147 | 153 | | |
148 | 154 | | |
| |||
0 commit comments