Test retry behavior under faults

Adapt an authored read-recovery specification, control the client scheduler and inspect HTTP faults without assuming an ordered chaos sequence.

Illustrative specification · synthetic data

A read recovers after one rate-limit response

This specification belongs in your client test suite. The fixture supplies the ordered responses, and the harness controls the client scheduler. The times below define the expected behavior of this case.

Copy and adapt this test specification

CASE: recover a read after a rate-limit response
Status: illustrative specification; synthetic data

INPUTS
Operation: read availability for item DEMO-7
Contract: read-only; this client may retry 429
Maximum attempts: 3 total, including the initial request
Total deadline: 2,500 ms from operation start
Attempt timeout: at most 500 ms, capped by time remaining
Local backoff: 250 ms; no jitter in this focused test
Server delay: honor valid Retry-After; use local backoff if absent/invalid
Next attempt: no earlier than both the local and server delay allow
Fixture: immediate 429 with Retry-After: 1, then 200 with quantity: 3
Harness: controlled client scheduler; requests and responses observable

EXPECTED EVENTS (relative to operation start)
0 ms       attempt 1 starts; fixture returns 429
0 ms       client schedules attempt 2 for 1,000 ms or later
999 ms     no second request has started
1,000 ms   scheduler permits attempt 2; fixture returns 200
completion caller receives quantity 3; no pending retry or attempt 3

FAILURE VARIANTS
All 429: stop after attempt 3; no attempt 4
Retry-After: 3: stop; the allowed retry would exceed the total deadline
Permanent error: stop after one attempt under this contract
No response: enforce attempt timeout and total deadline separately
Cancellation during wait: no later request starts

For the HTTP-date variant, supply the date corresponding to the same eligible time. For the duplicate-action case, use a separate write fixture that records an applied effect but drops its response; assert the recovery behavior required by that API’s contract.

Choose the smallest useful test environment

A stubbed transport and your test runner’s fake timers are often enough for a retry function. Use them when you only need an exact response sequence, parser branches or scheduler behavior.

Use an HTTP dependency environment when you also need to exercise real client routing, response handling or a shared integration case. With Gostly:

  1. Follow the quickstart, configure the selected service and verify one known response in MOCK mode.
  2. Use fault injection for supported errors and delays. Inspect the response condition actually delivered to the client.
  3. Run your client’s test and apply the assertions above. Save its policy, observed attempts, timing and final outcome with the API configuration.

Match the test to the control you have

A stochastic chaos preset does not establish “attempt 1 fails, attempt 2 succeeds.” Use a client-owned ordered fixture for that exact test, or assert behavior against the faults observed in your HTTP run.

Advancing simulated API time does not advance your app’s timers, SDK backoff or worker sleeps. Control and observe the client scheduler separately.

Use the chaos configuration and fault observability to identify the condition delivered. An injected before-response error can answer without reading a recording.

For retry policy, idempotency and assertion choices, read the retry-testing guide. The saved recovery walkthrough separately illustrates API-time advance and an explicit client retry.