(t *testing.T)
| 150 | } |
| 151 | |
| 152 | func TestMemoryList_CleanPrefix(t *testing.T) { |
| 153 | list := caches.NewMemoryList() |
| 154 | _ = list.Init() |
| 155 | before := time.Now() |
| 156 | var count = 100 |
| 157 | if testutils.IsSingleTesting() { |
| 158 | count = 1_000_000 |
| 159 | } |
| 160 | for i := 0; i < count; i++ { |
| 161 | key := "https://www.teaos.cn/hello/" + strconv.Itoa(i/10000) + "/" + strconv.Itoa(i) + ".html" |
| 162 | _ = list.Add(fmt.Sprintf("%d", xxhash.Sum64String(key)), &caches.Item{ |
| 163 | Key: key, |
| 164 | ExpiresAt: time.Now().Unix() + 3600, |
| 165 | BodySize: 0, |
| 166 | HeaderSize: 0, |
| 167 | }) |
| 168 | } |
| 169 | t.Log(time.Since(before).Seconds()*1000, "ms") |
| 170 | |
| 171 | before = time.Now() |
| 172 | err := list.CleanPrefix("https://www.teaos.cn/hello/10") |
| 173 | if err != nil { |
| 174 | t.Fatal(err) |
| 175 | } |
| 176 | |
| 177 | logs.Println(list.Stat(func(hash string) bool { |
| 178 | return true |
| 179 | })) |
| 180 | |
| 181 | t.Log(time.Since(before).Seconds()*1000, "ms") |
| 182 | } |
| 183 | |
| 184 | func TestMapRandomDelete(t *testing.T) { |
| 185 | var countMap = map[int]int{} // k => count |
nothing calls this directly
no test coverage detected