Error handling only gets tested when something actually fails. With Mockhop you can make an endpoint fail on purpose, in a way you control, so you can check retries, timeouts and fallbacks before a real outage does it for you.
Return an error for a share of calls
On a response, set an error probability, for example 0.1 for 10% of calls, along with the error status code (500 by default) and an optional error body. The other calls get the normal response, which is what a flaky dependency looks like.
Simulate a timeout
Set a timeout in milliseconds on a response. Mockhop waits that long and then answers:
HTTP/1.1 504 Gateway Timeout
{"error": "Request timeout (simulated)"}
Set your client's timeout below that value to see whether it gives up and retries the way you expect.
Make responses slow
Give a response a fixed delay, or a minimum and a maximum so each call waits a random time in between.
Rate limits
On the endpoint, turn on the rate limit and set the number of requests per time window in seconds, plus a burst. Above that, the endpoint answers with 429, so you can check that your client backs off.
Circuit breaker
Turn on the circuit breaker for an endpoint:
- After a set number of errors, it opens.
- After a timeout in seconds, it moves to half-open.
- Like a real dependency, it then closes again.
While it is open, the endpoint answers right away:
HTTP/1.1 503 Service Unavailable
X-Circuit-Breaker: open
Retry-After: 30
{"error": "Service temporarily unavailable (circuit breaker open)"}
Retry-After is the timeout you set, in seconds.
Pick the failure from your test
Matching rules choose a response by header, query parameter, body field or path segment. Give the endpoint a normal response and a second response with a rule such as header X-Case equals declined, returning 402. Your test then asks for the case it wants:
$ curl -s $URL/payments/charges \
-H "X-Case: declined"
Fail first, then succeed
To test a retry, use a scenario. With mode Once:
- step 1 answers
503 - step 2 answers
200
The first call fails, and every call after that succeeds. Each client session moves through the steps on its own.
Good to know
- Simulated errors, timeouts and 429s from your own rate limit are mock responses and count as requests. Limits the platform itself applies don't count.
- GraphQL resolvers have their own delay and error probability.
- A delay or timeout can be at most 55 seconds.
- Scenarios are included from the Pro plan; errors, delays, timeouts, rate limits and the circuit breaker are part of every plan.
New to Mockhop? Start with the quickstart. Plans: pricing.