Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scavenger suite #5498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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