swarm/storage/localstore: more correct testDB_collectGarbageWorker

This commit is contained in:
Janos Guljas 2019-02-21 23:05:31 +01:00
parent f25b2e026e
commit e65a7e4ac6
2 changed files with 1 additions and 10 deletions

View file

@ -134,7 +134,7 @@ func (db *DB) collectGarbageWorker() {
db.triggerGarbageCollection() db.triggerGarbageCollection()
} }
if testHookCollectGarbage != nil { if collectedCount > 0 && testHookCollectGarbage != nil {
testHookCollectGarbage(collectedCount) testHookCollectGarbage(collectedCount)
} }
case <-db.close: case <-db.close:

View file

@ -118,15 +118,6 @@ func testDB_collectGarbageWorker(t *testing.T) {
t.Fatal(err) 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 // TestDB_collectGarbageWorker_withRequests is a helper test function