swarm/storage/localstore: fix TestDB_collectGarbageWorker_withRequests

This commit is contained in:
Janos Guljas 2019-02-26 11:39:29 +01:00
parent 8af07768dd
commit 62d79bfbf0

View file

@ -156,6 +156,14 @@ func TestDB_collectGarbageWorker_withRequests(t *testing.T) {
addrs = append(addrs, chunk.Address()) addrs = append(addrs, chunk.Address())
} }
// set update gc test hook to signal when
// update gc goroutine is done by closing
// testHookUpdateGCChan channel
testHookUpdateGCChan := make(chan struct{})
resetTestHookUpdateGC := setTestHookUpdateGC(func() {
close(testHookUpdateGCChan)
})
// request the latest synced chunk // request the latest synced chunk
// to prioritize it in the gc index // to prioritize it in the gc index
// not to be collected // not to be collected
@ -164,6 +172,17 @@ func TestDB_collectGarbageWorker_withRequests(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// wait for update gc goroutine to finish for garbage
// collector to be correctly triggered after the last upload
select {
case <-testHookUpdateGCChan:
case <-time.After(10 * time.Second):
t.Fatal("updateGC was not called after getting chunk with ModeGetRequest")
}
// no need to wait for update gc hook anymore
resetTestHookUpdateGC()
// upload and sync another chunk to trigger // upload and sync another chunk to trigger
// garbage collection // garbage collection
ch := generateTestRandomChunk() ch := generateTestRandomChunk()