From 7ecc2714115c963641d2b89cc9fab90a590d9d5a Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Sun, 13 Nov 2016 18:21:42 +0100 Subject: [PATCH] Move Fatalf call into main test goroutine --- retrieval/scrape_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/retrieval/scrape_test.go b/retrieval/scrape_test.go index e07cbdc85..489d73c36 100644 --- a/retrieval/scrape_test.go +++ b/retrieval/scrape_test.go @@ -506,7 +506,7 @@ func TestTargetScrapeScrapeCancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - done := make(chan struct{}) + errc := make(chan error) go func() { time.Sleep(1 * time.Second) @@ -515,15 +515,18 @@ func TestTargetScrapeScrapeCancel(t *testing.T) { go func() { if _, err := ts.scrape(ctx, time.Now()); err != context.Canceled { - t.Fatalf("Expected context cancelation error but got: %s", err) + errc <- fmt.Errorf("Expected context cancelation error but got: %s", err) } - close(done) + close(errc) }() select { case <-time.After(5 * time.Second): t.Fatalf("Scrape function did not return unexpectedly") - case <-done: + case err := <-errc: + if err != nil { + t.Fatalf(err.Error()) + } } // If this is closed in a defer above the function the test server // does not terminate and the test doens't complete.