Skip to content

Commit 5223df7

Browse files
jbowensannrpom
authored andcommitted
storage/disk: deflake TestMonitorManager_monitorDisks
Use `require.Eventually` to deflake this test. Epic: none Fixes: #148556. Release note: none
1 parent 7f32131 commit 5223df7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/storage/disk/monitor_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package disk
77

88
import (
9+
"sync/atomic"
910
"testing"
1011
"time"
1112

@@ -17,13 +18,13 @@ import (
1718
)
1819

1920
type spyCollector struct {
20-
collectCallCount int
21+
collectCallCount atomic.Int32
2122
}
2223

2324
func (s *spyCollector) collect(
2425
disks []*monitoredDisk, now time.Time,
2526
) (countCollected int, err error) {
26-
s.collectCallCount++
27+
s.collectCallCount.Add(1)
2728
return len(disks), nil
2829
}
2930

@@ -45,9 +46,10 @@ func TestMonitorManager_monitorDisks(t *testing.T) {
4546
stop := make(chan struct{})
4647
go manager.monitorDisks(testCollector, stop)
4748

48-
time.Sleep(2 * DefaultDiskStatsPollingInterval)
49+
require.Eventually(t, func() bool {
50+
return testCollector.collectCallCount.Load() > 0
51+
}, 100*DefaultDiskStatsPollingInterval, DefaultDiskStatsPollingInterval)
4952
stop <- struct{}{}
50-
require.Greater(t, testCollector.collectCallCount, 0)
5153
}
5254

5355
func TestMonitor_StatsWindow(t *testing.T) {

0 commit comments

Comments
 (0)