(t *testing.T)
| 268 | } |
| 269 | |
| 270 | func 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 | |
| 302 | func BenchmarkMemoryList(b *testing.B) { |
| 303 | var list = caches.NewMemoryList() |
nothing calls this directly
no test coverage detected