@@ -27,8 +27,8 @@ import (
2727 "time"
2828
2929 "github.com/ethereum/go-ethereum/common"
30+ "github.com/ethereum/go-ethereum/log"
3031 "github.com/ethereum/go-ethereum/swarm/chunk"
31- "github.com/ethereum/go-ethereum/swarm/log"
3232 "github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
3333
3434 ldberrors "github.com/syndtr/goleveldb/leveldb/errors"
@@ -209,7 +209,7 @@ func testIterator(t *testing.T, mock bool) {
209209 for poc = 0 ; poc <= 255 ; poc ++ {
210210 err := db .SyncIterator (0 , uint64 (chunkkeys .Len ()), uint8 (poc ), func (k Address , n uint64 ) bool {
211211 log .Trace (fmt .Sprintf ("Got key %v number %d poc %d" , k , n , uint8 (poc )))
212- chunkkeys_results [n - 1 ] = k
212+ chunkkeys_results [n ] = k
213213 i ++
214214 return true
215215 })
@@ -324,12 +324,12 @@ func TestLDBStoreWithoutCollectGarbage(t *testing.T) {
324324 log .Info ("got back chunk" , "chunk" , ret )
325325 }
326326
327- if ldb .entryCnt != uint64 (n + 1 ) {
328- t .Fatalf ("expected entryCnt to be equal to %v, but got %v" , n + 1 , ldb .entryCnt )
327+ if ldb .entryCnt != uint64 (n ) {
328+ t .Fatalf ("expected entryCnt to be equal to %v, but got %v" , n , ldb .entryCnt )
329329 }
330330
331- if ldb .accessCnt != uint64 (2 * n + 1 ) {
332- t .Fatalf ("expected accessCnt to be equal to %v, but got %v" , n + 1 , ldb .accessCnt )
331+ if ldb .accessCnt != uint64 (2 * n ) {
332+ t .Fatalf ("expected accessCnt to be equal to %v, but got %v" , 2 * n , ldb .accessCnt )
333333 }
334334}
335335
@@ -362,7 +362,7 @@ func TestLDBStoreCollectGarbage(t *testing.T) {
362362 log .Info ("ldbstore" , "entrycnt" , ldb .entryCnt , "accesscnt" , ldb .accessCnt )
363363
364364 // wait for garbage collection to kick in on the responsible actor
365- time .Sleep (5 * time .Second )
365+ time .Sleep (1 * time .Second )
366366
367367 var missing int
368368 for i := 0 ; i < n ; i ++ {
@@ -416,14 +416,7 @@ func TestLDBStoreAddRemove(t *testing.T) {
416416 for i := 0 ; i < n ; i ++ {
417417 // delete all even index chunks
418418 if i % 2 == 0 {
419-
420- key := chunks [i ].Addr
421- ikey := getIndexKey (key )
422-
423- var indx dpaDBIndex
424- ldb .tryAccessIdx (ikey , & indx )
425-
426- ldb .delete (indx .Idx , ikey , ldb .po (key ))
419+ ldb .Delete (chunks [i ].Addr )
427420 }
428421 }
429422
@@ -452,12 +445,12 @@ func TestLDBStoreAddRemove(t *testing.T) {
452445
453446// TestLDBStoreRemoveThenCollectGarbage tests that we can delete chunks and that we can trigger garbage collection
454447func TestLDBStoreRemoveThenCollectGarbage (t * testing.T ) {
455- capacity := 10
448+ capacity := 11
456449
457450 ldb , cleanup := newLDBStore (t )
458451 ldb .setCapacity (uint64 (capacity ))
459452
460- n := 7
453+ n := 11
461454
462455 chunks := []* Chunk {}
463456 for i := 0 ; i < capacity ; i ++ {
@@ -477,23 +470,18 @@ func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
477470
478471 // delete all chunks
479472 for i := 0 ; i < n ; i ++ {
480- key := chunks [i ].Addr
481- ikey := getIndexKey (key )
482-
483- var indx dpaDBIndex
484- ldb .tryAccessIdx (ikey , & indx )
485-
486- ldb .delete (indx .Idx , ikey , ldb .po (key ))
473+ ldb .Delete (chunks [i ].Addr )
487474 }
488475
489476 log .Info ("ldbstore" , "entrycnt" , ldb .entryCnt , "accesscnt" , ldb .accessCnt )
490477
491478 cleanup ()
492479
493480 ldb , cleanup = newLDBStore (t )
481+ capacity = 10
494482 ldb .setCapacity (uint64 (capacity ))
495483
496- n = 10
484+ n = 11
497485
498486 for i := 0 ; i < n ; i ++ {
499487 ldb .Put (context .TODO (), chunks [i ])
@@ -504,6 +492,9 @@ func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
504492 <- chunks [i ].dbStoredC
505493 }
506494
495+ // wait for garbage collection
496+ time .Sleep (1 * time .Second )
497+
507498 // expect for first chunk to be missing, because it has the smallest access value
508499 idx := 0
509500 ret , err := ldb .Get (context .TODO (), chunks [idx ].Addr )
0 commit comments