diff --git a/swarm/storage/localstore/gc.go b/swarm/storage/localstore/gc.go index 50fbfe6fec..ebaba2d8f3 100644 --- a/swarm/storage/localstore/gc.go +++ b/swarm/storage/localstore/gc.go @@ -134,7 +134,7 @@ func (db *DB) collectGarbageWorker() { db.triggerGarbageCollection() } - if testHookCollectGarbage != nil { + if collectedCount > 0 && testHookCollectGarbage != nil { testHookCollectGarbage(collectedCount) } case <-db.close: diff --git a/swarm/storage/localstore/gc_test.go b/swarm/storage/localstore/gc_test.go index 5515d6dd2c..60309d7fa9 100644 --- a/swarm/storage/localstore/gc_test.go +++ b/swarm/storage/localstore/gc_test.go @@ -118,15 +118,6 @@ func testDB_collectGarbageWorker(t *testing.T) { t.Fatal(err) } }) - - // cleanup: drain the last testHookCollectGarbageChan - // element before calling deferred functions not to block - // collectGarbageWorker loop, preventing the race in - // setting testHookCollectGarbage function - select { - case <-testHookCollectGarbageChan: - default: - } } // TestDB_collectGarbageWorker_withRequests is a helper test function