| 265 | } |
| 266 | |
| 267 | func TestRetryLoopContextDeadline(t *testing.T) { |
| 268 | var invoked atomic.Bool |
| 269 | worker := func() (shouldRetry bool, err error, value any) { |
| 270 | invoked.Store(true) |
| 271 | return true, nil, nil |
| 272 | } |
| 273 | |
| 274 | ctx, cancelFunc := context.WithTimeout(TestCtx(t), 50*time.Millisecond) |
| 275 | defer cancelFunc() |
| 276 | |
| 277 | err, _ := RetryLoop(ctx, t.Name(), worker, CreateIndefiniteMaxDoublingSleeperFunc(10, 100)) |
| 278 | require.ErrorContains(t, err, "timed out based on context") |
| 279 | require.ErrorIs(t, err, context.DeadlineExceeded) |
| 280 | require.ErrorIs(t, ctx.Err(), context.DeadlineExceeded) |
| 281 | } |
| 282 | |
| 283 | func TestSyncSourceFromURL(t *testing.T) { |
| 284 | u, err := url.Parse("http://www.test.com:4985/mydb") |