aboutsummaryrefslogtreecommitdiffstats
path: root/evict_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'evict_test.go')
-rw-r--r--evict_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/evict_test.go b/evict_test.go
index ba73c24..1813e94 100644
--- a/evict_test.go
+++ b/evict_test.go
@@ -86,6 +86,36 @@ func TestFIFOPolicy(t *testing.T) {
assert.Nil(t, policy.Evict())
})
})
+
+ t.Run("Eviction Order", func(t *testing.T) {
+ t.Parallel()
+
+ policy := lfuPolicy{evict: createSentinel(t)}
+
+ n0 := &node{Key: []byte("0"), Access: 1}
+ n1 := &node{Key: []byte("1"), Access: 1}
+
+ policy.OnInsert(n0)
+ policy.OnInsert(n1)
+
+ evictedNode := policy.Evict()
+ assert.Same(t, n0, evictedNode) // Assuming FIFO order for same access count
+ })
+
+ t.Run("With Zero TTL", func(t *testing.T) {
+ t.Parallel()
+
+ policy := ltrPolicy{evict: createSentinel(t), evictZero: false}
+
+ n0 := &node{Key: []byte("0"), Expiration: time.Time{}}
+ n1 := &node{Key: []byte("1"), Expiration: time.Now().Add(1 * time.Hour)}
+
+ policy.OnInsert(n0)
+ policy.OnInsert(n1)
+
+ evictedNode := policy.Evict()
+ assert.Same(t, n1, evictedNode) // n0 should not be evicted due to zero TTL
+ })
}
func TestLRUPolicy(t *testing.T) {