From 62d79bfbf0467e5f156e630f05f5505cf597823b Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Tue, 26 Feb 2019 11:39:29 +0100 Subject: [PATCH] swarm/storage/localstore: fix TestDB_collectGarbageWorker_withRequests --- swarm/storage/localstore/gc_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/swarm/storage/localstore/gc_test.go b/swarm/storage/localstore/gc_test.go index 4526f93076..3964c16d59 100644 --- a/swarm/storage/localstore/gc_test.go +++ b/swarm/storage/localstore/gc_test.go @@ -156,6 +156,14 @@ func TestDB_collectGarbageWorker_withRequests(t *testing.T) { 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 // to prioritize it in the gc index // not to be collected @@ -164,6 +172,17 @@ func TestDB_collectGarbageWorker_withRequests(t *testing.T) { 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 // garbage collection ch := generateTestRandomChunk()