Skip to content

Commit

Permalink
test: convert the example in issue allegro#300 into a test case
Browse files Browse the repository at this point in the history
The new commit-id 16df11e can fix the issue
  • Loading branch information
docxsyang committed Nov 18, 2021
1 parent 16df11e commit 0fe2494
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bigcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,3 +1132,29 @@ func TestCache_RepeatedSetWithBiggerEntry(t *testing.T) {
}

}

// TestBigCache_allocateAdditionalMemoryLeadPanic
// The new commit 16df11e change the encoding method,it can fix issue #300
func TestBigCache_allocateAdditionalMemoryLeadPanic(t *testing.T){
t.Parallel()
cache, _ := NewBigCache(Config{
Shards: 1,
LifeWindow: 3 * time.Second,
MaxEntrySize: 52,
})
cache.Set("a", blob(0xff, 235))
time.Sleep(2 * time.Second)
cache.Set("b", blob(0xff, 235))
// expire the first element
time.Sleep(2 * time.Second)
// insert the before head
cache.Set("c", blob(0xff, 108))
// reallocate the memory
cache.Set("d", blob(0xff, 1024))
time.Sleep(4 * time.Second)
cache.Set("e", blob(0xff, 3))
cache.Set("f", blob(0xff, 3))
cache.Set("g", blob(0xff, 3))
data,_:= cache.Get("g")
assertEqual(t, []byte{0xff,0xff,0xff}, data)
}

0 comments on commit 0fe2494

Please sign in to comment.