-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache_test.go
More file actions
37 lines (27 loc) · 732 Bytes
/
cache_test.go
File metadata and controls
37 lines (27 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package evcache_test
import (
"runtime"
"testing"
"time"
"github.com/mgnsk/evcache/v4"
. "github.com/mgnsk/evcache/v4/internal/testing"
)
func TestCacheGoGC(t *testing.T) {
capacity := 1_000_000
c := evcache.New[int, struct{}](evcache.WithCapacity(capacity))
for i := range capacity {
c.StoreTTL(i, struct{}{}, time.Hour) // Store with TTL to trigger the cleanup runner.
}
var stats runtime.MemStats
runtime.ReadMemStats(&stats)
t.Logf("alloc before:\t%d bytes", stats.Alloc)
oldSize := stats.Alloc
runtime.KeepAlive(c)
EventuallyTrue(t, func() bool {
runtime.GC()
runtime.ReadMemStats(&stats)
newSize := stats.Alloc
return newSize < oldSize/2
})
t.Logf("alloc after:\t%d bytes", stats.Alloc)
}