File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -107,11 +107,18 @@ func TestGlobalMemoryTuner(t *testing.T) {
107107 require .Eventually (t , func () bool {
108108 return GlobalMemoryLimitTuner .calcMemoryLimit (fallbackPercentage ) == debug .SetMemoryLimit (- 1 )
109109 }, 5 * time .Second , 100 * time .Millisecond )
110- gcNum = getNowGCNum ()
110+ memoryLimitGCTotal := memory . MemoryLimitGCTotal . Load ()
111111 memory100mb := allocator .alloc (100 << 20 )
112- require .Eventually (t , func () bool {
113- return gcNum == getNowGCNum ()
114- }, 5 * time .Second , 100 * time .Millisecond ) // No GC
112+ // This window used to assert "no GC at all" via NumGC, but that is inherently
113+ // timing-sensitive: unrelated background GCs (or test harness GCs) can happen
114+ // here without violating the intent of this test.
115+ //
116+ // What we really need to assert is: while MemoryLimit is in fallback mode,
117+ // allocating more memory should not immediately cause an extra *memory-limit*
118+ // GC/adjust cycle.
119+ require .Never (t , func () bool {
120+ return memoryLimitGCTotal != memory .MemoryLimitGCTotal .Load ()
121+ }, 500 * time .Millisecond , 100 * time .Millisecond )
115122
116123 allocator .free (memory210mb )
117124 allocator .free (memory100mb )
You can’t perform that action at this time.
0 commit comments