common/lru: add test case for BasicLRU.Peek (#27559)

This commit is contained in:
Sanghee Choi 2023-06-27 17:27:40 +09:00 committed by GitHub
parent d7ea278fe3
commit 900591299f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) { func BenchmarkLRU(b *testing.B) {
var ( var (
capacity = 1000 capacity = 1000