Skip to content

Commit fc67a42

Browse files
author
Thomas Stromberg
committed
add regression test for deletion after eviction
1 parent 29195df commit fc67a42

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎s3fifo_delete_regression_test.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,24 @@ func TestS3FIFO_InsertionPanicReleasesLock(t *testing.T) {
7171
}
7272
c.mu.Unlock()
7373
}
74+
75+
// Reproduce the production failure using public operations only: retain a
76+
// once-read entry during eviction, invalidate it, then keep inserting.
77+
func TestCacheDeleteAfterEviction(t *testing.T) {
78+
c := New[int, int](Size(8))
79+
for i := 0; i < 8; i++ {
80+
c.Set(i, i)
81+
}
82+
c.Get(0)
83+
c.Set(8, 8)
84+
c.Delete(0)
85+
if c.Len() != 8 {
86+
t.Fatalf("deleting an evicted entry changed live count to %d", c.Len())
87+
}
88+
for i := 9; i < 100; i++ {
89+
c.Set(i, i)
90+
}
91+
if got, ok := c.Get(99); !ok || got != 99 {
92+
t.Fatalf("cache stopped after invalidation: %d %v", got, ok)
93+
}
94+
}

0 commit comments

Comments
 (0)