From 6fa429cf42c4aa110db299a0e320ee502310881d Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 14 Oct 2019 19:44:28 +0200 Subject: [PATCH] Unflake TestGoCollectorGoroutines This is not a great solution, but it's also hard to test for this moving target. Signed-off-by: beorn7 --- prometheus/go_collector_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/prometheus/go_collector_test.go b/prometheus/go_collector_test.go index 3d8d94e..a929acf 100644 --- a/prometheus/go_collector_test.go +++ b/prometheus/go_collector_test.go @@ -44,9 +44,14 @@ func TestGoCollectorGoroutines(t *testing.T) { go func() { c.Collect(metricCh) - go func(c <-chan struct{}) { - <-c - }(endGoroutineCh) + for i := 1; i <= 10; i++ { + // Start 10 goroutines to be sure we'll detect an + // increase even if unrelated goroutines happen to + // terminate during this test. + go func(c <-chan struct{}) { + <-c + }(endGoroutineCh) + } <-waitCh c.Collect(metricCh) close(endCollectionCh) @@ -73,9 +78,8 @@ func TestGoCollectorGoroutines(t *testing.T) { continue } - if diff := int(pb.GetGauge().GetValue()) - old; diff != 1 { - // TODO: This is flaky in highly concurrent situations. - t.Errorf("want 1 new goroutine, got %d", diff) + if diff := old - int(pb.GetGauge().GetValue()); diff > -1 { + t.Errorf("want at least one new goroutine, got %d fewer", diff) } case <-time.After(1 * time.Second): t.Fatalf("expected collect timed out")