MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestCache_Memory

Function TestCache_Memory

internal/ttlcache/cache_test.go:47–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestCache_Memory(t *testing.T) {
48 if !testutils.IsSingleTesting() {
49 return
50 }
51
52 var cache = NewCache[int]()
53 var isReady bool
54
55 testutils.StartMemoryStats(t, func() {
56 if !isReady {
57 return
58 }
59 t.Log(cache.Count(), "items")
60 })
61
62 var count = 1_000_000
63 if memutils.SystemMemoryGB() > 4 {
64 count = 20_000_000
65 }
66 for i := 0; i < count; i++ {
67 cache.Write("a"+strconv.Itoa(i), 1, time.Now().Unix()+int64(rands.Int(0, 300)))
68 }
69
70 func() {
71 var before = time.Now()
72 runtime.GC()
73 var costSeconds = time.Since(before).Seconds()
74 var stats = &debug.GCStats{}
75 debug.ReadGCStats(stats)
76 t.Log("GC pause:", stats.Pause[0].Seconds()*1000, "ms", "cost:", costSeconds*1000, "ms")
77 }()
78
79 isReady = true
80
81 t.Log(cache.Count())
82
83 time.Sleep(10 * time.Second)
84 for i := 0; i < count; i++ {
85 if i%2 == 0 {
86 cache.Delete("a" + strconv.Itoa(i))
87 }
88 }
89
90 t.Log(cache.Count())
91
92 cache.Count()
93
94 time.Sleep(3600 * time.Second)
95}
96
97func TestCache_IncreaseInt64(t *testing.T) {
98 var a = assert.NewAssertion(t)

Callers

nothing calls this directly

Calls 8

IsSingleTestingFunction · 0.92
StartMemoryStatsFunction · 0.92
LogMethod · 0.80
UnixMethod · 0.80
CountMethod · 0.65
WriteMethod · 0.65
GCMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected