Skip to content

Commit 216bd2c

Browse files
janoszelig
authored andcommitted
swarm/storage/localstore: fix testDB_collectGarbageWorker data race (#19206)
1 parent a1099bb commit 216bd2c

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎swarm/storage/localstore/gc_test.go‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ func testDB_collectGarbageWorker(t *testing.T) {
5151

5252
chunkCount := 150
5353

54-
testHookCollectGarbageChan := make(chan int64)
55-
defer setTestHookCollectGarbage(func(collectedCount int64) {
56-
testHookCollectGarbageChan <- collectedCount
57-
})()
58-
5954
db, cleanupFunc := newTestDB(t, &Options{
6055
Capacity: 100,
6156
})
57+
testHookCollectGarbageChan := make(chan int64)
58+
defer setTestHookCollectGarbage(func(collectedCount int64) {
59+
select {
60+
case testHookCollectGarbageChan <- collectedCount:
61+
case <-db.close:
62+
}
63+
})()
6264
defer cleanupFunc()
6365

6466
uploader := db.NewPutter(ModePutUpload)

0 commit comments

Comments
 (0)