MCPcopy
hub / github.com/bsm/redislock / TestLock_Refresh_retry_transient_error

Function TestLock_Refresh_retry_transient_error

redislock_test.go:263–285  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

261}
262
263func TestLock_Refresh_retry_transient_error(t *testing.T) {
264 rc := redisConnect(t)
265 flaky := &flakyScripter{Client: rc.Client}
266 client := New(flaky)
267
268 lock, err := client.Obtain(t.Context(), rc.lockKey(), time.Hour, nil)
269 if err != nil {
270 t.Fatal(err)
271 }
272 defer lock.Release(t.Context())
273
274 // fail the next 2 refresh attempts; the 3rd should succeed.
275 flaky.fails.Store(2)
276 if err := lock.Refresh(t.Context(), time.Minute, &Options{
277 RetryStrategy: LimitRetry(LinearBackoff(5*time.Millisecond), 5),
278 }); err != nil {
279 t.Fatalf("expected refresh to recover, got %v", err)
280 }
281 if remaining := flaky.fails.Load(); remaining != 0 {
282 t.Fatalf("expected all injected failures to be consumed, %d remaining", remaining)
283 }
284 assertTTL(t, lock, time.Minute)
285}
286
287func TestLock_Refresh_retry_transient_error_exhausted(t *testing.T) {
288 rc := redisConnect(t)

Callers

nothing calls this directly

Calls 9

redisConnectFunction · 0.85
NewFunction · 0.85
LimitRetryFunction · 0.85
LinearBackoffFunction · 0.85
assertTTLFunction · 0.85
ObtainMethod · 0.80
lockKeyMethod · 0.80
ReleaseMethod · 0.80
RefreshMethod · 0.80

Tested by

no test coverage detected