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 <paulin.todev@gmail.com>
This commit is contained in:
Paulin Todev 2023-11-23 11:24:08 +00:00 committed by GitHub
parent 2329fba0e5
commit 0102425af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 8 deletions

View File

@ -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()