swarm/storage: fix data races in TestLDBStoreCollectGarbage

This commit is contained in:
Janos Guljas 2019-01-16 16:33:54 +01:00
parent 4aeeecfded
commit be56353a0e

View file

@ -388,7 +388,9 @@ func testLDBStoreCollectGarbage(t *testing.T) {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
allChunks = append(allChunks, chunks...) allChunks = append(allChunks, chunks...)
ldb.lock.Lock()
log.Debug("ldbstore", "entrycnt", ldb.entryCnt, "accesscnt", ldb.accessCnt, "cap", capacity, "n", n) log.Debug("ldbstore", "entrycnt", ldb.entryCnt, "accesscnt", ldb.accessCnt, "cap", capacity, "n", n)
ldb.lock.Unlock()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel() defer cancel()
@ -537,7 +539,9 @@ func testLDBStoreRemoveThenCollectGarbage(t *testing.T) {
remaining -= putCount remaining -= putCount
for putCount > 0 { for putCount > 0 {
ldb.Put(context.TODO(), chunks[puts]) ldb.Put(context.TODO(), chunks[puts])
ldb.lock.Lock()
log.Debug("ldbstore", "entrycnt", ldb.entryCnt, "accesscnt", ldb.accessCnt, "cap", capacity, "n", n, "puts", puts, "remaining", remaining, "roundtarget", roundTarget) log.Debug("ldbstore", "entrycnt", ldb.entryCnt, "accesscnt", ldb.accessCnt, "cap", capacity, "n", n, "puts", puts, "remaining", remaining, "roundtarget", roundTarget)
ldb.lock.Unlock()
puts++ puts++
putCount-- putCount--
} }