(t *testing.T, memcache *cache.Memcached)
| 35 | } |
| 36 | |
| 37 | func 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. |
| 73 | type mockMemcacheFailing struct { |
no test coverage detected