Skip to content

Commit

Permalink
common/lru: add test case for BasicLRU.Peek (#27559)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengin7384 authored Jun 27, 2023
1 parent d7ea278 commit 9005912
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/lru/basiclru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ func TestBasicLRUContains(t *testing.T) {
}
}

// Test that Peek doesn't update recent-ness
func TestBasicLRUPeek(t *testing.T) {
cache := NewBasicLRU[int, int](2)
cache.Add(1, 1)
cache.Add(2, 2)
if v, ok := cache.Peek(1); !ok || v != 1 {
t.Errorf("1 should be set to 1")
}
cache.Add(3, 3)
if cache.Contains(1) {
t.Errorf("should not have updated recent-ness of 1")
}
}

func BenchmarkLRU(b *testing.B) {
var (
capacity = 1000
Expand Down

0 comments on commit 9005912

Please sign in to comment.