MCPcopy
hub / github.com/grafana/dskit / TestMemcachedClient_GetMultiWithError

Function TestMemcachedClient_GetMultiWithError

cache/memcached_client_test.go:160–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

158}
159
160func TestMemcachedClient_GetMultiWithError(t *testing.T) {
161 t.Run("returns error from backend", func(t *testing.T) {
162 backendErr := fmt.Errorf("connection failed")
163 backend := &erroringMockMemcachedClientBackend{
164 mockMemcachedClientBackend: newMockMemcachedClientBackend(),
165 err: backendErr,
166 }
167 client, err := newMemcachedClient(
168 log.NewNopLogger(),
169 backend,
170 &mockServerSelector{
171 servers: []mockServer{
172 {addr: "127.0.0.1:11211"},
173 },
174 },
175 MemcachedClientConfig{
176 Addresses: []string{"localhost"},
177 MaxAsyncConcurrency: 1,
178 MaxAsyncBufferSize: 10,
179 },
180 prometheus.NewPedanticRegistry(),
181 "test",
182 )
183 require.NoError(t, err)
184
185 ctx := context.Background()
186 res, err := client.GetMultiWithError(ctx, []string{"foo"})
187 require.ErrorIs(t, err, backendErr)
188 require.Empty(t, res)
189 })
190
191 t.Run("returns partial results with error", func(t *testing.T) {
192 backendErr := fmt.Errorf("connection failed")
193 backend := &selectiveErrorMockMemcachedClientBackend{
194 mockMemcachedClientBackend: newMockMemcachedClientBackend(),
195 failOnCalls: map[int]error{2: backendErr}, // Fail on 2nd batch
196 }
197
198 client, err := newMemcachedClient(
199 log.NewNopLogger(),
200 backend,
201 &mockServerSelector{
202 servers: []mockServer{
203 {addr: "127.0.0.1:11211"},
204 },
205 },
206 MemcachedClientConfig{
207 Addresses: []string{"localhost"},
208 MaxAsyncConcurrency: 1,
209 MaxAsyncBufferSize: 10,
210 MaxGetMultiBatchSize: 1, // Force each key into its own batch
211 },
212 prometheus.NewPedanticRegistry(),
213 "test",
214 )
215 require.NoError(t, err)
216
217 // Set up 3 keys

Callers

nothing calls this directly

Calls 6

newMemcachedClientFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.80
GetMultiWithErrorMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected