scrape tests: Make appenders more realistic (#7594)

With this, the storage tests inside the scrape package are more
realistic.

Discovered with #7593, but fixed independently as #7593 will probably
take some time.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-07-17 12:30:22 +02:00 committed by GitHub
parent a69a8b931f
commit 22aa21e508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -648,15 +648,13 @@ func TestScrapeLoopSeriesAdded(t *testing.T) {
s := teststorage.New(t) s := teststorage.New(t)
defer s.Close() defer s.Close()
app := s.Appender()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
sl := newScrapeLoop(ctx, sl := newScrapeLoop(ctx,
&testScraper{}, &testScraper{},
nil, nil, nil, nil,
nopMutator, nopMutator,
nopMutator, nopMutator,
func() storage.Appender { return app }, s.Appender,
nil, nil,
0, 0,
true, true,
@ -793,13 +791,11 @@ func TestScrapeLoopCache(t *testing.T) {
s := teststorage.New(t) s := teststorage.New(t)
defer s.Close() defer s.Close()
sapp := s.Appender() appender := &collectResultAppender{}
appender := &collectResultAppender{next: sapp}
var ( var (
signal = make(chan struct{}, 1) signal = make(chan struct{}, 1)
scraper = &testScraper{} scraper = &testScraper{}
app = func() storage.Appender { return appender } app = func() storage.Appender { appender.next = s.Appender(); return appender }
) )
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -1141,15 +1137,13 @@ func TestScrapeLoop_ChangingMetricString(t *testing.T) {
s := teststorage.New(t) s := teststorage.New(t)
defer s.Close() defer s.Close()
app := s.Appender() capp := &collectResultAppender{}
capp := &collectResultAppender{next: app}
sl := newScrapeLoop(context.Background(), sl := newScrapeLoop(context.Background(),
nil, nil, nil, nil, nil, nil,
nopMutator, nopMutator,
nopMutator, nopMutator,
func() storage.Appender { return capp }, func() storage.Appender { capp.next = s.Appender(); return capp },
nil, nil,
0, 0,
true, true,
@ -1628,15 +1622,13 @@ func TestScrapeLoopDiscardDuplicateLabels(t *testing.T) {
s := teststorage.New(t) s := teststorage.New(t)
defer s.Close() defer s.Close()
app := s.Appender()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
sl := newScrapeLoop(ctx, sl := newScrapeLoop(ctx,
&testScraper{}, &testScraper{},
nil, nil, nil, nil,
nopMutator, nopMutator,
nopMutator, nopMutator,
func() storage.Appender { return app }, s.Appender,
nil, nil,
0, 0,
true, true,
@ -1896,15 +1888,13 @@ func TestScrapeAddFast(t *testing.T) {
s := teststorage.New(t) s := teststorage.New(t)
defer s.Close() defer s.Close()
app := s.Appender()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
sl := newScrapeLoop(ctx, sl := newScrapeLoop(ctx,
&testScraper{}, &testScraper{},
nil, nil, nil, nil,
nopMutator, nopMutator,
nopMutator, nopMutator,
func() storage.Appender { return app }, s.Appender,
nil, nil,
0, 0,
true, true,