MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / TestNewCache

Function TestNewCache

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

Source from the content-addressed store, hash-verified

17)
18
19func TestNewCache(t *testing.T) {
20 var cache = NewCache[int]()
21 cache.Write("a", 1, time.Now().Unix()+3600)
22 cache.Write("b", 2, time.Now().Unix()+1)
23 cache.Write("c", 1, time.Now().Unix()+3602)
24 cache.Write("d", 1, time.Now().Unix()+1)
25
26 for _, piece := range cache.pieces {
27 if len(piece.m) > 0 {
28 for k, item := range piece.m {
29 t.Log(k, "=>", item.Value, item.expiredAt)
30 }
31 }
32 }
33 t.Log("a:", cache.Read("a"))
34 if testutils.IsSingleTesting() {
35 time.Sleep(5 * time.Second)
36 }
37
38 for i := 0; i < len(cache.pieces); i++ {
39 cache.GC()
40 }
41
42 t.Log("b:", cache.Read("b"))
43 t.Log("d:", cache.Read("d"))
44 t.Log("left:", cache.Count(), "items")
45}
46
47func TestCache_Memory(t *testing.T) {
48 if !testutils.IsSingleTesting() {

Callers

nothing calls this directly

Calls 7

IsSingleTestingFunction · 0.92
UnixMethod · 0.80
LogMethod · 0.80
WriteMethod · 0.65
ReadMethod · 0.65
GCMethod · 0.65
CountMethod · 0.65

Tested by

no test coverage detected