Skip to content

Commit

Permalink
fix leaky log from scavenger test suite (#5498)
Browse files Browse the repository at this point in the history
  • Loading branch information
3vilhamster authored Dec 19, 2023
1 parent cf47922 commit e869984
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 9 additions & 2 deletions service/worker/scanner/tasklist/scavenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions service/worker/scanner/tasklist/scavenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e869984

Please sign in to comment.