From 55568f8bdf1dd0643d728a844f6e77bd963f2628 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Tue, 19 Dec 2023 11:23:35 +0100 Subject: [PATCH] fix leaky log from scavenger test suite --- service/worker/scanner/tasklist/scavenger.go | 11 +++++++++-- service/worker/scanner/tasklist/scavenger_test.go | 10 +--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/service/worker/scanner/tasklist/scavenger.go b/service/worker/scanner/tasklist/scavenger.go index 9436d9ecb22..353e3d47060 100644 --- a/service/worker/scanner/tasklist/scavenger.go +++ b/service/worker/scanner/tasklist/scavenger.go @@ -54,13 +54,18 @@ type ( logger log.Logger stats stats status int32 - stopC chan struct{} - stopWG sync.WaitGroup getOrphanTasksPageSizeFn dynamicconfig.IntPropertyFn taskBatchSizeFn dynamicconfig.IntPropertyFn maxTasksPerJobFn dynamicconfig.IntPropertyFn cleanOrphans dynamicconfig.BoolPropertyFn pollInterval time.Duration + + // stopC is used to signal the scavenger to stop + stopC chan struct{} + // stopWG is used to wait for the scavenger to stop + stopWG sync.WaitGroup + // stoppedC is closed once the scavenger is stopped + stopped chan struct{} } stats struct { @@ -166,6 +171,7 @@ func NewScavenger( scope: metricsClient.Scope(metrics.TaskListScavengerScope), logger: logger, stopC: make(chan struct{}), + stopped: make(chan struct{}), executor: taskExecutor, cleanOrphans: cleanOrphans, taskBatchSizeFn: taskBatchSizeFn, @@ -199,6 +205,7 @@ func (s *Scavenger) Stop() { s.executor.Stop() s.stopWG.Wait() s.logger.Info("Tasklist scavenger stopped") + close(s.stopped) } // Alive returns true if the scavenger is still running diff --git a/service/worker/scanner/tasklist/scavenger_test.go b/service/worker/scanner/tasklist/scavenger_test.go index 113cd782007..118ee13bdef 100644 --- a/service/worker/scanner/tasklist/scavenger_test.go +++ b/service/worker/scanner/tasklist/scavenger_test.go @@ -193,16 +193,8 @@ func (s *ScavengerTestSuite) TestAllExpiredTasksWithErrors() { func (s *ScavengerTestSuite) runScavenger() { s.scvgr.Start() timer := time.NewTimer(scavengerTestTimeout) - - waiter := make(chan struct{}) - - go func() { - s.scvgr.stopWG.Wait() - close(waiter) - }() - select { - case <-waiter: + case <-s.scvgr.stopped: timer.Stop() return case <-timer.C: