File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -44,9 +44,14 @@ func TestGoCollectorGoroutines(t *testing.T) {
44
44
45
45
go func () {
46
46
c .Collect (metricCh )
47
- go func (c <- chan struct {}) {
48
- <- c
49
- }(endGoroutineCh )
47
+ for i := 1 ; i <= 10 ; i ++ {
48
+ // Start 10 goroutines to be sure we'll detect an
49
+ // increase even if unrelated goroutines happen to
50
+ // terminate during this test.
51
+ go func (c <- chan struct {}) {
52
+ <- c
53
+ }(endGoroutineCh )
54
+ }
50
55
<- waitCh
51
56
c .Collect (metricCh )
52
57
close (endCollectionCh )
@@ -73,9 +78,8 @@ func TestGoCollectorGoroutines(t *testing.T) {
73
78
continue
74
79
}
75
80
76
- if diff := int (pb .GetGauge ().GetValue ()) - old ; diff != 1 {
77
- // TODO: This is flaky in highly concurrent situations.
78
- t .Errorf ("want 1 new goroutine, got %d" , diff )
81
+ if diff := old - int (pb .GetGauge ().GetValue ()); diff > - 1 {
82
+ t .Errorf ("want at least one new goroutine, got %d fewer" , diff )
79
83
}
80
84
case <- time .After (1 * time .Second ):
81
85
t .Fatalf ("expected collect timed out" )
You can’t perform that action at this time.
0 commit comments