MCPcopy Create free account
hub / github.com/cortexproject/cortex / testMemcache

Function testMemcache

pkg/chunk/cache/memcached_test.go:37–70  ·  view source on GitHub ↗
(t *testing.T, memcache *cache.Memcached)

Source from the content-addressed store, hash-verified

35}
36
37func testMemcache(t *testing.T, memcache *cache.Memcached) {
38 numKeys := 1000
39
40 ctx := context.Background()
41 keysIncMissing := make([]string, 0, numKeys)
42 keys := make([]string, 0, numKeys)
43 bufs := make([][]byte, 0, numKeys)
44
45 // Insert 1000 keys skipping all multiples of 5.
46 for i := range numKeys {
47 keysIncMissing = append(keysIncMissing, fmt.Sprint(i))
48 if i%5 == 0 {
49 continue
50 }
51
52 keys = append(keys, fmt.Sprint(i))
53 bufs = append(bufs, fmt.Append(nil, i))
54 }
55 memcache.Store(ctx, keys, bufs)
56
57 found, bufs, missing := memcache.Fetch(ctx, keysIncMissing)
58 for i := range numKeys {
59 if i%5 == 0 {
60 require.Equal(t, fmt.Sprint(i), missing[0])
61 missing = missing[1:]
62 continue
63 }
64
65 require.Equal(t, fmt.Sprint(i), found[0])
66 require.Equal(t, fmt.Sprint(i), string(bufs[0]))
67 found = found[1:]
68 bufs = bufs[1:]
69 }
70}
71
72// mockMemcache whose calls fail 1/3rd of the time.
73type mockMemcacheFailing struct {

Callers 1

TestMemcachedFunction · 0.85

Calls 4

AppendMethod · 0.80
StoreMethod · 0.65
FetchMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected