fix: gc only do once (#32722)

issue: #29655

produced by pr: #31740

Signed-off-by: chyezh <chyezh@outlook.com>
This commit is contained in:
chyezh 2024-04-30 14:19:27 +08:00 committed by GitHub
parent b6c06ff2c3
commit 77f4f0c5a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View File

@ -174,7 +174,7 @@ func (gc *garbageCollector) work(ctx context.Context) {
}
// startControlLoop start a control loop for garbageCollector.
func (gc *garbageCollector) startControlLoop(ctx context.Context) {
func (gc *garbageCollector) startControlLoop(_ context.Context) {
for {
select {
case cmd := <-gc.cmdCh:
@ -203,7 +203,7 @@ func (gc *garbageCollector) startControlLoop(ctx context.Context) {
// runRecycleTaskWithPauser is a helper function to create a task with pauser
func (gc *garbageCollector) runRecycleTaskWithPauser(ctx context.Context, name string, interval time.Duration, task func(ctx context.Context)) {
logger := log.With(zap.String("gcType", name)).With(zap.Duration("interval", interval))
timer := time.NewTimer(interval)
timer := time.NewTicker(interval)
defer timer.Stop()
for {

View File

@ -1614,6 +1614,26 @@ func (s *GarbageCollectorSuite) TestPauseResume() {
})
}
func (s *GarbageCollectorSuite) TestRunRecycleTaskWithPauser() {
gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{
cli: s.cli,
enabled: true,
checkInterval: time.Millisecond * 10,
scanInterval: time.Hour * 7 * 24,
missingTolerance: time.Hour * 24,
dropTolerance: time.Hour * 24,
})
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*2500)
defer cancel()
cnt := 0
gc.runRecycleTaskWithPauser(ctx, "test", time.Second, func(ctx context.Context) {
cnt++
})
s.Equal(cnt, 2)
}
func TestGarbageCollector(t *testing.T) {
suite.Run(t, new(GarbageCollectorSuite))
}