Skip to content

Commit

Permalink
scrape_test: add scrape offset in test scraper to avoid race
Browse files Browse the repository at this point in the history
This change adds an offset to the test scraper so a scrape is not
initiated when the context is cancelled. Without this change, there
was a race between the context cancellation and the scrape jitter wait
and this change fixes that.

Can verify using:
go test -run ^TestScrapeLoopStopBeforeRun$ github.com/prometheus/prometheus/scrape -race -count 1000

Signed-off-by: Ridwan Sharif <ridwanmsharif@google.com>
  • Loading branch information
ridwanmsharif authored and bwplotka committed Nov 20, 2023
1 parent 842a791 commit 5e5cf36
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scrape/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ func TestScrapeLoopStopBeforeRun(t *testing.T) {
nil,
)

// The loop must terminate during the initial offset if the context
// is canceled.
scraper.offsetDur = time.Hour

// The scrape pool synchronizes on stopping scrape loops. However, new scrape
// loops are started asynchronously. Thus it's possible, that a loop is stopped
// again before having started properly.
Expand Down

0 comments on commit 5e5cf36

Please sign in to comment.