File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 6
6
package disk
7
7
8
8
import (
9
+ "sync/atomic"
9
10
"testing"
10
11
"time"
11
12
@@ -17,13 +18,13 @@ import (
17
18
)
18
19
19
20
type spyCollector struct {
20
- collectCallCount int
21
+ collectCallCount atomic. Int32
21
22
}
22
23
23
24
func (s * spyCollector ) collect (
24
25
disks []* monitoredDisk , now time.Time ,
25
26
) (countCollected int , err error ) {
26
- s .collectCallCount ++
27
+ s .collectCallCount . Add ( 1 )
27
28
return len (disks ), nil
28
29
}
29
30
@@ -45,9 +46,10 @@ func TestMonitorManager_monitorDisks(t *testing.T) {
45
46
stop := make (chan struct {})
46
47
go manager .monitorDisks (testCollector , stop )
47
48
48
- time .Sleep (2 * DefaultDiskStatsPollingInterval )
49
+ require .Eventually (t , func () bool {
50
+ return testCollector .collectCallCount .Load () > 0
51
+ }, 100 * DefaultDiskStatsPollingInterval , DefaultDiskStatsPollingInterval )
49
52
stop <- struct {}{}
50
- require .Greater (t , testCollector .collectCallCount , 0 )
51
53
}
52
54
53
55
func TestMonitor_StatsWindow (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments