Skip to content

Commit

Permalink
add shard list back tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Mar 30, 2024
1 parent b9e0583 commit 53e8e26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lru_shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ func TestLRUShardPadding(t *testing.T) {
if n := unsafe.Sizeof(s); n != 128 {
t.Errorf("shard size is %d, not 128", n)
}
}

func TestLRUShardListSet(t *testing.T) {
var s lrushard[string, uint32]
s.Init(1024, getRuntimeHasher[string](), 0)

key := "foobar"
hash := uint32(s.table_hasher(noescape(unsafe.Pointer(&key)), s.table_seed))

s.Set(hash, key, 42)

if index := s.list_Back(); s.list[index].key == key {
t.Errorf("foobar should be list back: %v %v", index, s.list[index].key)
}
}

func TestLRUShardTableSet(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions ttl_shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ func TestTTLShardPadding(t *testing.T) {
if n := unsafe.Sizeof(s); n != 128 {
t.Errorf("shard size is %d, not 128", n)
}
}

func TestTTLShardListSet(t *testing.T) {
var s ttlshard[string, uint32]
s.Init(1024, getRuntimeHasher[string](), 0)

key := "foobar"
hash := uint32(s.table_hasher(noescape(unsafe.Pointer(&key)), s.table_seed))

s.Set(hash, key, 42, 0)

if index := s.list_Back(); s.list[index].key == key {
t.Errorf("foobar should be list back: %v %v", index, s.list[index].key)
}
}

func TestTTLShardTableSet(t *testing.T) {
Expand Down

0 comments on commit 53e8e26

Please sign in to comment.