Skip to content

Commit 72e4f29

Browse files
committed
db: fix TestCleanupManagerCloseWithPacing
This test is ineffective because the `FreeSpaceThresholdBytes` option disables pacing. Fix by setting that option to 1 byte. We also remove the extra checking of `stopCh` - if it is closed, we will exit the pacing loop right away so there's no need for this special check.
1 parent d8efa29 commit 72e4f29

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

obsolete_files.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,7 @@ func (cm *cleanupManager) mainLoop() {
185185
// Use a token bucket with 1 token / second refill rate and 1 token burst.
186186
tb.Init(1.0, 1.0)
187187
for job := range cm.jobsCh {
188-
select {
189-
case <-cm.stopCh:
190-
cm.deleteObsoleteFilesInJob(job, nil, nil)
191-
default:
192-
cm.deleteObsoleteFilesInJob(job, &tb, paceTimer)
193-
}
188+
cm.deleteObsoleteFilesInJob(job, &tb, paceTimer)
194189
cm.mu.Lock()
195190
cm.mu.completedJobs++
196191
cm.mu.completedStats.Add(job.stats)
@@ -247,6 +242,7 @@ func (cm *cleanupManager) maybePace(
247242
select {
248243
case <-paceTimer.C:
249244
case <-cm.stopCh:
245+
// The cleanup manager is being closed. Delete without pacing.
250246
return
251247
}
252248
}

obsolete_files_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ func TestCleaner(t *testing.T) {
145145
func TestCleanupManagerCloseWithPacing(t *testing.T) {
146146
mem := vfs.NewMem()
147147
opts := &Options{
148-
FS: mem,
149-
TargetByteDeletionRate: 1024, // 1 KB/s - slow pacing
148+
FS: mem,
149+
FreeSpaceThresholdBytes: 1,
150+
TargetByteDeletionRate: 1024, // 1 KB/s - slow pacing
150151
}
151152
opts.EnsureDefaults()
152153

@@ -160,6 +161,7 @@ func TestCleanupManagerCloseWithPacing(t *testing.T) {
160161
getDeletePacerInfo := func() deletionPacerInfo {
161162
return deletionPacerInfo{
162163
freeBytes: 10 << 30,
164+
liveBytes: 10 << 30,
163165
}
164166
}
165167

0 commit comments

Comments
 (0)