Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed May 14, 2024
1 parent 62ad954 commit 49ce3d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
8 changes: 4 additions & 4 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ func (s *PersistentSlabStorage) getAllChildReferences(slab Slab) (

// BatchPreload decodeds and caches slabs of given ids in parallel.
// This is useful for storage health or data validation in migration programs.
func (s *PersistentSlabStorage) BatchPreload(ids []SlabID, numWorkers int) error {
func (s *PersistentSlabStorage) BatchPreload(ids []StorageID, numWorkers int) error {
if len(ids) == 0 {
return nil
}
Expand Down Expand Up @@ -1566,12 +1566,12 @@ func (s *PersistentSlabStorage) BatchPreload(ids []SlabID, numWorkers int) error
}

type slabToBeDecoded struct {
slabID SlabID
slabID StorageID
data []byte
}

type decodedSlab struct {
slabID SlabID
slabID StorageID
slab Slab
err error
}
Expand Down Expand Up @@ -1628,7 +1628,7 @@ func (s *PersistentSlabStorage) BatchPreload(ids []SlabID, numWorkers int) error

// Preallocate cache map if empty
if len(s.cache) == 0 {
s.cache = make(map[SlabID]Slab, len(ids))
s.cache = make(map[StorageID]Slab, len(ids))
}

// Launch workers
Expand Down
20 changes: 10 additions & 10 deletions storage_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ func benchmarkRetrieve(b *testing.B, seed int64, numberOfSlabs int) {
decMode, err := cbor.DecOptions{}.DecMode()
require.NoError(b, err)

encodedSlabs := make(map[SlabID][]byte)
ids := make([]SlabID, 0, numberOfSlabs)
encodedSlabs := make(map[StorageID][]byte)
ids := make([]StorageID, 0, numberOfSlabs)
for i := 0; i < numberOfSlabs; i++ {
addr := generateRandomAddress(r)

var index SlabIndex
var index StorageIndex
binary.BigEndian.PutUint64(index[:], uint64(i))

id := SlabID{addr, index}
id := StorageID{addr, index}

slab := generateLargeSlab(id)

data, err := EncodeSlab(slab, encMode)
data, err := Encode(slab, encMode)
require.NoError(b, err)

encodedSlabs[id] = data
Expand Down Expand Up @@ -190,19 +190,19 @@ func benchmarkBatchPreload(b *testing.B, seed int64, numberOfSlabs int) {
decMode, err := cbor.DecOptions{}.DecMode()
require.NoError(b, err)

encodedSlabs := make(map[SlabID][]byte)
ids := make([]SlabID, 0, numberOfSlabs)
encodedSlabs := make(map[StorageID][]byte)
ids := make([]StorageID, 0, numberOfSlabs)
for i := 0; i < numberOfSlabs; i++ {
addr := generateRandomAddress(r)

var index SlabIndex
var index StorageIndex
binary.BigEndian.PutUint64(index[:], uint64(i))

id := SlabID{addr, index}
id := StorageID{addr, index}

slab := generateLargeSlab(id)

data, err := EncodeSlab(slab, encMode)
data, err := Encode(slab, encMode)
require.NoError(b, err)

encodedSlabs[id] = data
Expand Down
34 changes: 17 additions & 17 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4970,15 +4970,15 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe

indexesByAddress := make(map[Address]uint64)

generateSlabID := func(address Address) SlabID {
generateSlabID := func(address Address) StorageID {
nextIndex := indexesByAddress[address] + 1

var idx SlabIndex
var idx StorageIndex
binary.BigEndian.PutUint64(idx[:], nextIndex)

indexesByAddress[address] = nextIndex

return NewSlabID(address, idx)
return NewStorageID(address, idx)
}

encMode, err := cbor.EncOptions{}.EncMode()
Expand All @@ -4989,7 +4989,7 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe

r := newRand(t)

encodedSlabs := make(map[SlabID][]byte)
encodedSlabs := make(map[StorageID][]byte)

// Generate and encode slabs
for i := 0; i < numberOfAccounts; i++ {
Expand All @@ -5002,15 +5002,15 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe

slab := generateRandomSlab(slabID, r)

encodedSlabs[slabID], err = EncodeSlab(slab, encMode)
encodedSlabs[slabID], err = Encode(slab, encMode)
require.NoError(t, err)
}
}

baseStorage := NewInMemBaseStorageFromMap(encodedSlabs)
storage := NewPersistentSlabStorage(baseStorage, encMode, decMode, decodeStorable, decodeTypeInfo)

ids := make([]SlabID, 0, len(encodedSlabs))
ids := make([]StorageID, 0, len(encodedSlabs))
for id := range encodedSlabs {
ids = append(ids, id)
}
Expand All @@ -5023,7 +5023,7 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe

// Compare encoded data
for id, data := range encodedSlabs {
cachedData, err := EncodeSlab(storage.cache[id], encMode)
cachedData, err := Encode(storage.cache[id], encMode)
require.NoError(t, err)

require.Equal(t, cachedData, data)
Expand All @@ -5043,12 +5043,12 @@ func TestStorageBatchPreloadNotFoundSlabs(t *testing.T) {
t.Run("empty storage", func(t *testing.T) {
const numberOfSlabs = 10

ids := make([]SlabID, numberOfSlabs)
ids := make([]StorageID, numberOfSlabs)
for i := 0; i < numberOfSlabs; i++ {
var index SlabIndex
var index StorageIndex
binary.BigEndian.PutUint64(index[:], uint64(i))

ids[i] = NewSlabID(generateRandomAddress(r), index)
ids[i] = NewStorageID(generateRandomAddress(r), index)
}

baseStorage := NewInMemBaseStorage()
Expand All @@ -5064,25 +5064,25 @@ func TestStorageBatchPreloadNotFoundSlabs(t *testing.T) {
t.Run("non-empty storage", func(t *testing.T) {
const numberOfSlabs = 10

ids := make([]SlabID, numberOfSlabs)
encodedSlabs := make(map[SlabID][]byte)
ids := make([]StorageID, numberOfSlabs)
encodedSlabs := make(map[StorageID][]byte)

for i := 0; i < numberOfSlabs; i++ {
var index SlabIndex
var index StorageIndex
binary.BigEndian.PutUint64(index[:], uint64(i))

id := NewSlabID(generateRandomAddress(r), index)
id := NewStorageID(generateRandomAddress(r), index)

slab := generateRandomSlab(id, r)

encodedSlabs[id], err = EncodeSlab(slab, encMode)
encodedSlabs[id], err = Encode(slab, encMode)
require.NoError(t, err)

ids[i] = id
}

// Append a slab ID that doesn't exist in storage.
ids = append(ids, NewSlabID(generateRandomAddress(r), SlabIndex{numberOfSlabs}))
ids = append(ids, NewStorageID(generateRandomAddress(r), StorageIndex{numberOfSlabs}))

baseStorage := NewInMemBaseStorageFromMap(encodedSlabs)
storage := NewPersistentSlabStorage(baseStorage, encMode, decMode, decodeStorable, decodeTypeInfo)
Expand All @@ -5095,7 +5095,7 @@ func TestStorageBatchPreloadNotFoundSlabs(t *testing.T) {

// Compare encoded data
for id, data := range encodedSlabs {
cachedData, err := EncodeSlab(storage.cache[id], encMode)
cachedData, err := Encode(storage.cache[id], encMode)
require.NoError(t, err)

require.Equal(t, cachedData, data)
Expand Down

0 comments on commit 49ce3d2

Please sign in to comment.