(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func 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 | |
| 97 | func TestCache_IncreaseInt64(t *testing.T) { |
| 98 | var a = assert.NewAssertion(t) |
nothing calls this directly
no test coverage detected