mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
scrape: fix goroutine leak in test (#6812)
* scrape: fix goroutine leak in test Signed-off-by: BurtonQin <bobbqqin@gmail.com>
This commit is contained in:
parent
135cc30063
commit
cdbd42393e
|
@ -427,7 +427,7 @@ func nopMutator(l labels.Labels) labels.Labels { return l }
|
||||||
|
|
||||||
func TestScrapeLoopStop(t *testing.T) {
|
func TestScrapeLoopStop(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
signal = make(chan struct{})
|
signal = make(chan struct{}, 1)
|
||||||
appender = &collectResultAppender{}
|
appender = &collectResultAppender{}
|
||||||
scraper = &testScraper{}
|
scraper = &testScraper{}
|
||||||
app = func() storage.Appender { return appender }
|
app = func() storage.Appender { return appender }
|
||||||
|
@ -492,7 +492,7 @@ func TestScrapeLoopStop(t *testing.T) {
|
||||||
|
|
||||||
func TestScrapeLoopRun(t *testing.T) {
|
func TestScrapeLoopRun(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
signal = make(chan struct{})
|
signal = make(chan struct{}, 1)
|
||||||
errc = make(chan error)
|
errc = make(chan error)
|
||||||
|
|
||||||
scraper = &testScraper{}
|
scraper = &testScraper{}
|
||||||
|
@ -676,7 +676,7 @@ func TestScrapeLoopSeriesAdded(t *testing.T) {
|
||||||
func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
|
func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
|
||||||
appender := &collectResultAppender{}
|
appender := &collectResultAppender{}
|
||||||
var (
|
var (
|
||||||
signal = make(chan struct{})
|
signal = make(chan struct{}, 1)
|
||||||
scraper = &testScraper{}
|
scraper = &testScraper{}
|
||||||
app = func() storage.Appender { return appender }
|
app = func() storage.Appender { return appender }
|
||||||
)
|
)
|
||||||
|
@ -730,7 +730,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
|
||||||
func TestScrapeLoopRunCreatesStaleMarkersOnParseFailure(t *testing.T) {
|
func TestScrapeLoopRunCreatesStaleMarkersOnParseFailure(t *testing.T) {
|
||||||
appender := &collectResultAppender{}
|
appender := &collectResultAppender{}
|
||||||
var (
|
var (
|
||||||
signal = make(chan struct{})
|
signal = make(chan struct{}, 1)
|
||||||
scraper = &testScraper{}
|
scraper = &testScraper{}
|
||||||
app = func() storage.Appender { return appender }
|
app = func() storage.Appender { return appender }
|
||||||
numScrapes = 0
|
numScrapes = 0
|
||||||
|
@ -793,7 +793,7 @@ func TestScrapeLoopCache(t *testing.T) {
|
||||||
|
|
||||||
appender := &collectResultAppender{next: sapp}
|
appender := &collectResultAppender{next: sapp}
|
||||||
var (
|
var (
|
||||||
signal = make(chan struct{})
|
signal = make(chan struct{}, 1)
|
||||||
scraper = &testScraper{}
|
scraper = &testScraper{}
|
||||||
app = func() storage.Appender { return appender }
|
app = func() storage.Appender { return appender }
|
||||||
)
|
)
|
||||||
|
@ -871,7 +871,7 @@ func TestScrapeLoopCacheMemoryExhaustionProtection(t *testing.T) {
|
||||||
|
|
||||||
appender := &collectResultAppender{next: sapp}
|
appender := &collectResultAppender{next: sapp}
|
||||||
var (
|
var (
|
||||||
signal = make(chan struct{})
|
signal = make(chan struct{}, 1)
|
||||||
scraper = &testScraper{}
|
scraper = &testScraper{}
|
||||||
app = func() storage.Appender { return appender }
|
app = func() storage.Appender { return appender }
|
||||||
)
|
)
|
||||||
|
@ -1408,7 +1408,7 @@ func TestTargetScrapeScrapeCancel(t *testing.T) {
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
errc := make(chan error)
|
errc := make(chan error, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
@ -1421,8 +1421,9 @@ func TestTargetScrapeScrapeCancel(t *testing.T) {
|
||||||
errc <- errors.New("Expected error but got nil")
|
errc <- errors.New("Expected error but got nil")
|
||||||
} else if ctx.Err() != context.Canceled {
|
} else if ctx.Err() != context.Canceled {
|
||||||
errc <- errors.Errorf("Expected context cancellation error but got: %s", ctx.Err())
|
errc <- errors.Errorf("Expected context cancellation error but got: %s", ctx.Err())
|
||||||
|
} else {
|
||||||
|
close(errc)
|
||||||
}
|
}
|
||||||
close(errc)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Reference in a new issue