(t *testing.T, memcache *cache.Memcached)
| 98 | } |
| 99 | |
| 100 | func testMemcacheFailing(t *testing.T, memcache *cache.Memcached) { |
| 101 | numKeys := 1000 |
| 102 | |
| 103 | ctx := context.Background() |
| 104 | keysIncMissing := make([]string, 0, numKeys) |
| 105 | keys := make([]string, 0, numKeys) |
| 106 | bufs := make([][]byte, 0, numKeys) |
| 107 | // Insert 1000 keys skipping all multiples of 5. |
| 108 | for i := 0; i < numKeys; i++ { |
| 109 | keysIncMissing = append(keysIncMissing, fmt.Sprint(i)) |
| 110 | if i%5 == 0 { |
| 111 | continue |
| 112 | } |
| 113 | keys = append(keys, fmt.Sprint(i)) |
| 114 | bufs = append(bufs, []byte(fmt.Sprint(i))) |
| 115 | } |
| 116 | memcache.Store(ctx, keys, bufs) |
| 117 | |
| 118 | for i := 0; i < 10; i++ { |
| 119 | found, bufs, missing := memcache.Fetch(ctx, keysIncMissing) |
| 120 | |
| 121 | require.Equal(t, len(found), len(bufs)) |
| 122 | for i := range found { |
| 123 | require.Equal(t, found[i], string(bufs[i])) |
| 124 | } |
| 125 | |
| 126 | keysReturned := make(map[string]struct{}) |
| 127 | for _, key := range found { |
| 128 | _, ok := keysReturned[key] |
| 129 | require.False(t, ok, "duplicate key returned") |
| 130 | |
| 131 | keysReturned[key] = struct{}{} |
| 132 | } |
| 133 | for _, key := range missing { |
| 134 | _, ok := keysReturned[key] |
| 135 | require.False(t, ok, "duplicate key returned") |
| 136 | |
| 137 | keysReturned[key] = struct{}{} |
| 138 | } |
| 139 | |
| 140 | for _, key := range keys { |
| 141 | _, ok := keysReturned[key] |
| 142 | require.True(t, ok, "key missing %s", key) |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | func TestMemcacheStop(t *testing.T) { |
| 148 | t.Run("unbatched", func(_ *testing.T) { |
no test coverage detected