Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cache: fix test flakiness by stopping the chunk cleaner promptly

Nick Craig-Wood63439b44445c
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index 06644b1be..6e4f2973c 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -503,15 +503,19 @@ func NewFs(ctx context.Context, name, rootPath string, m configmap.Mapper) (fs.F
}
go func() {
+ // Wait on the timer and the stop channel together so that a stop
+ // signalled by StopBackgroundRunners is honoured immediately.
+ timer := time.NewTimer(time.Duration(f.opt.ChunkCleanInterval))
+ defer timer.Stop()
for {
- time.Sleep(time.Duration(f.opt.ChunkCleanInterval))
select {
case <-f.cleanupChan:
fs.Infof(f, "stopping cleanup")
return
- default:
+ case <-timer.C:
fs.Debugf(f, "starting cleanup")
f.CleanUpCache(false)
+ timer.Reset(time.Duration(f.opt.ChunkCleanInterval))
}
}
}()