瀏覽代碼

swarm/storage/localstore: fix testDB_collectGarbageWorker data race (#19206)

Janoš Guljaš 6 年之前
父節點
當前提交
216bd2ceba
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      swarm/storage/localstore/gc_test.go

+ 7 - 5
swarm/storage/localstore/gc_test.go

@@ -51,14 +51,16 @@ func testDB_collectGarbageWorker(t *testing.T) {
 
 	chunkCount := 150
 
-	testHookCollectGarbageChan := make(chan int64)
-	defer setTestHookCollectGarbage(func(collectedCount int64) {
-		testHookCollectGarbageChan <- collectedCount
-	})()
-
 	db, cleanupFunc := newTestDB(t, &Options{
 		Capacity: 100,
 	})
+	testHookCollectGarbageChan := make(chan int64)
+	defer setTestHookCollectGarbage(func(collectedCount int64) {
+		select {
+		case testHookCollectGarbageChan <- collectedCount:
+		case <-db.close:
+		}
+	})()
 	defer cleanupFunc()
 
 	uploader := db.NewPutter(ModePutUpload)