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

Function TestMemoryList_CleanPrefix

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

Source from the content-addressed store, hash-verified

150}
151
152func 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
184func TestMapRandomDelete(t *testing.T) {
185 var countMap = map[int]int{} // k => count

Callers

nothing calls this directly

Calls 8

InitMethod · 0.95
AddMethod · 0.95
CleanPrefixMethod · 0.95
StatMethod · 0.95
NewMemoryListFunction · 0.92
IsSingleTestingFunction · 0.92
UnixMethod · 0.80
LogMethod · 0.80

Tested by

no test coverage detected