From 0102425af102bddb7be64af9abb93af7ba5193ea Mon Sep 17 00:00:00 2001 From: Paulin Todev Date: Thu, 23 Nov 2023 11:24:08 +0000 Subject: [PATCH] Use only one scrapeMetrics object per test. (#13051) The scrape loop and scrape cache should use the same instance. This brings the tests' behavior more in line with production. Signed-off-by: Paulin Todev --- scrape/scrape_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index 238e90c204..5e4f3f30c7 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -792,8 +792,9 @@ func TestScrapeLoopRun(t *testing.T) { signal = make(chan struct{}, 1) errc = make(chan error) - scraper = &testScraper{} - app = func(ctx context.Context) storage.Appender { return &nopAppender{} } + scraper = &testScraper{} + app = func(ctx context.Context) storage.Appender { return &nopAppender{} } + scrapeMetrics = newTestScrapeMetrics(t) ) ctx, cancel := context.WithCancel(context.Background()) @@ -817,7 +818,7 @@ func TestScrapeLoopRun(t *testing.T) { false, nil, false, - newTestScrapeMetrics(t), + scrapeMetrics, ) // The loop must terminate during the initial offset if the context @@ -876,7 +877,7 @@ func TestScrapeLoopRun(t *testing.T) { false, nil, false, - newTestScrapeMetrics(t), + scrapeMetrics, ) go func() { @@ -974,9 +975,10 @@ func TestScrapeLoopForcedErr(t *testing.T) { func TestScrapeLoopMetadata(t *testing.T) { var ( - signal = make(chan struct{}) - scraper = &testScraper{} - cache = newScrapeCache(newTestScrapeMetrics(t)) + signal = make(chan struct{}) + scraper = &testScraper{} + scrapeMetrics = newTestScrapeMetrics(t) + cache = newScrapeCache(scrapeMetrics) ) defer close(signal) @@ -1001,7 +1003,7 @@ func TestScrapeLoopMetadata(t *testing.T) { false, nil, false, - newTestScrapeMetrics(t), + scrapeMetrics, ) defer cancel()