Skip to content

Commit c6056f8

Browse files
authored
gctuner: make TestGlobalMemoryTuner resilient to background GC (#68169)
close #67174
1 parent a58b358 commit c6056f8

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

pkg/util/gctuner/memory_limit_tuner_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)