Skip to content

Commit

Permalink
Test setting a lot of items
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest committed Dec 13, 2024
1 parent 7069e9b commit e20b047
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
3 changes: 1 addition & 2 deletions space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ func (s *Space[K, V]) set(
}

// Add pointer node.
var err error
volatileAddress, err = s.addPointerNode(v, tx, volatileAllocator, conflict)
volatileAddress, err := s.addPointerNode(v, tx, volatileAllocator, conflict)
if err != nil {
return err
}
Expand Down
73 changes: 72 additions & 1 deletion space/space_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Github actions run on machines not supporting AVX-512 instructions.
//go:build nogithub
////go:build nogithub

package space

Expand Down Expand Up @@ -2152,3 +2152,74 @@ func TestSetTheSameSlotTwiceUsingDifferentEntry(t *testing.T) {
requireT.True(exists)
requireT.Equal(txtypes.Amount(10), balance)
}

// TestSetManyItems sets a lot of items to trigger node splits and parent node creations.
func TestSetManyItems(t *testing.T) {
requireT := require.New(t)

const numOfItems = 1000

state := alloc.NewForTest(t, stateSize)

s := NewSpaceTest[uint64, uint64](t, state, nil)

for i := range uint64(numOfItems) {
v := s.NewEntry(TestKey[uint64]{
Key: i,
KeyHash: types.KeyHash(i + 1),
}, StageData)
requireT.NoError(s.SetKey(v, i))
}

for i := range uint64(numOfItems) {
key := TestKey[uint64]{
Key: i,
KeyHash: types.KeyHash(i + 1),
}

v := s.NewEntry(key, StageData)
requireT.True(s.KeyExists(v))
requireT.Equal(i, s.ReadKey(v))

value, exists := s.Query(key)
requireT.True(exists)
requireT.Equal(i, value)
}
}

// TestSetManyItems sets a lot of items with conflicting key hash to trigger node splits and parent node creations.
func TestSetManyItemsWithConflicts(t *testing.T) {
requireT := require.New(t)

const (
keyHash = 1
numOfItems = 1000
)

state := alloc.NewForTest(t, stateSize)

s := NewSpaceTest[uint64, uint64](t, state, nil)

for i := range uint64(numOfItems) {
v := s.NewEntry(TestKey[uint64]{
Key: i,
KeyHash: keyHash,
}, StageData)
requireT.NoError(s.SetKey(v, i))
}

for i := range uint64(numOfItems) {
key := TestKey[uint64]{
Key: i,
KeyHash: keyHash,
}

v := s.NewEntry(key, StageData)
requireT.True(s.KeyExists(v))
requireT.Equal(i, s.ReadKey(v))

value, exists := s.Query(key)
requireT.True(exists)
requireT.Equal(i, value)
}
}

0 comments on commit e20b047

Please sign in to comment.