Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: convert the example in issue #300 into a test case #302

Merged
merged 9 commits into from
Dec 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not sleep in tests. Please use mockedClock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced time.Sleep with mockedClock.Please take a look

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)
}
janisz marked this conversation as resolved.
Show resolved Hide resolved