Skip to content

Commit c13325c

Browse files
authored
Merge pull request #655 from prometheus/beorn7/test
Unflake TestGoCollectorGoroutines
2 parents 8b3e008 + 6fa429c commit c13325c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

prometheus/go_collector_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ func TestGoCollectorGoroutines(t *testing.T) {
4444

4545
go func() {
4646
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+
}
5055
<-waitCh
5156
c.Collect(metricCh)
5257
close(endCollectionCh)
@@ -73,9 +78,8 @@ func TestGoCollectorGoroutines(t *testing.T) {
7378
continue
7479
}
7580

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)
7983
}
8084
case <-time.After(1 * time.Second):
8185
t.Fatalf("expected collect timed out")

0 commit comments

Comments
 (0)