MCPcopy Index your code
hub / github.com/golang/groupcache / TestCacheEviction

Function TestCacheEviction

groupcache_test.go:189–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

187}
188
189func TestCacheEviction(t *testing.T) {
190 once.Do(testSetup)
191 testKey := "TestCacheEviction-key"
192 getTestKey := func() {
193 var res string
194 for i := 0; i < 10; i++ {
195 if err := stringGroup.Get(dummyCtx, testKey, StringSink(&res)); err != nil {
196 t.Fatal(err)
197 }
198 }
199 }
200 fills := countFills(getTestKey)
201 if fills != 1 {
202 t.Fatalf("expected 1 cache fill; got %d", fills)
203 }
204
205 g := stringGroup.(*Group)
206 evict0 := g.mainCache.nevict
207
208 // Trash the cache with other keys.
209 var bytesFlooded int64
210 // cacheSize/len(testKey) is approximate
211 for bytesFlooded < cacheSize+1024 {
212 var res string
213 key := fmt.Sprintf("dummy-key-%d", bytesFlooded)
214 stringGroup.Get(dummyCtx, key, StringSink(&res))
215 bytesFlooded += int64(len(key) + len(res))
216 }
217 evicts := g.mainCache.nevict - evict0
218 if evicts <= 0 {
219 t.Errorf("evicts = %v; want more than 0", evicts)
220 }
221
222 // Test that the key is gone.
223 fills = countFills(getTestKey)
224 if fills != 1 {
225 t.Fatalf("expected 1 cache fill after cache trashing; got %d", fills)
226 }
227}
228
229type fakePeer struct {
230 hits int

Callers

nothing calls this directly

Calls 4

StringSinkFunction · 0.85
countFillsFunction · 0.85
DoMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…