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

Function TestMemoryList_GC

internal/caches/list_memory_test.go:270–300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

268}
269
270func TestMemoryList_GC(t *testing.T) {
271 if !testutils.IsSingleTesting() {
272 return
273 }
274
275 list := caches.NewMemoryList().(*caches.MemoryList)
276 _ = list.Init()
277 for i := 0; i < 1_000_000; i++ {
278 key := "https://www.teaos.cn/hello" + strconv.Itoa(i/100000) + "/" + strconv.Itoa(i) + ".html"
279 _ = list.Add(fmt.Sprintf("%d", xxhash.Sum64String(key)), &caches.Item{
280 Key: key,
281 ExpiresAt: 0,
282 BodySize: 0,
283 HeaderSize: 0,
284 })
285 }
286 t.Log("clean...", len(list.ItemMaps()))
287 _ = list.CleanAll()
288 t.Log("cleanAll...", len(list.ItemMaps()))
289 before := time.Now()
290 //runtime.GC()
291 t.Log("gc cost:", time.Since(before).Seconds()*1000, "ms")
292
293 if testutils.IsSingleTesting() {
294 timeout := time.NewTimer(2 * time.Minute)
295 <-timeout.C
296 t.Log("2 minutes passed")
297
298 time.Sleep(30 * time.Minute)
299 }
300}
301
302func BenchmarkMemoryList(b *testing.B) {
303 var list = caches.NewMemoryList()

Callers

nothing calls this directly

Calls 7

IsSingleTestingFunction · 0.92
NewMemoryListFunction · 0.92
LogMethod · 0.80
ItemMapsMethod · 0.80
InitMethod · 0.65
AddMethod · 0.65
CleanAllMethod · 0.65

Tested by

no test coverage detected