Introducing WireMock Chaos: API Mocking Meets Chaos Engineering

Robert Elliot
Senior Software Engineer
March 2, 2023

In the real world, APIs break. The new Chaos feature lets you simulate complex failure scenarios – and build more resilient API dependencies. Read on to learn how it works or try it yourself.

What happens when an API you depend on is down? In the best case, not much. Your app fails gracefully, informs the user that some functionality is temporarily unavailable, and periodically tries to call the API again until it receives the coveted 200 response. In the worst case, it triggers a domino effect where upstream services fail one after another. In the meantime, your app keeps flooding an already-overloaded API server with additional requests.

How do you make sure that your app behaves well when other services are misbehaving? That's where chaos engineering comes in. And with the latest update to WireMock Cloud, you can implement it in your API testing in a single-digit amount of clicks.

Order From Chaos

Originally developed at Netflix, chaos engineering is a practice that enables development teams to proactively test the resilience of their systems. You intentionally introduce controlled failure scenarios (like network latency or API response delays) and measure their impact on the system. This way, you can identify weaknesses and develop strategies to make your systems more fault-tolerant.

What does this have to do with API mocking? If you’ve ever developed against a 3rd party API – or even an internal service where the devs were still ‘ironing out some kinks’ – you’ll know that APIs can and will fail. Timeouts, network failures, or unexpected error statuses are an everyday occurrence. Your API mock should reflect this reality, so you can learn how to build more resilience into your app. 

WireMock Chaos: Inject Complex Failure States Into Your Mocked APIs

The newest addition to WireMock Cloud lets you simulate a wide range of API failure scenarios. By introducing random chaos elements, you’ll be able to stress-test your app against the type of trouble it’s likely to encounter in the wild.

For example, if you’re mocking a payments gateway API such as Paypal or Stripe, you’ll be able to see how your app functions in case this API has a long delay, an outage, or occasional timeouts.

The benefits

  • Easily simulate failure scenarios that are hard to simulate: See how your app handles fail states that happen in the network layer rather than the application layer (invalid HTTP, socket reset, socket close).
  • Run more realistic integration tests: Understand how your entire app responds to an API failing, so you can identify and mitigate any upstream outages.
  • Avoid disasters in production: Find out if any API error is a showstopper in your test environment, rather than through angry support tickets.
  • Shift-left testing. WireMock’s chaos feature allows certain types of testing to run more quickly in scaled-down, isolated environments, allowing many problems to be uncovered earlier and at lower costs.

Enabling and Configuring Chaos

  1. Navigate to the Performance tab in the WireMock Cloud web UI.
  2. Use the toggle to enable chaos. 
  3. Choose which percent of requests you want to fail, and how you want them to fail. We currently support five failure modes: socket close, socket reset, invalid HTTP,  long delay, and HTTP error statuses. 
  4. Set the overall percentage of failures. WireMock will distribute each enabled failure mode evenly out of this total.
  5. Toggle ‘Enable chaos’, sit back, and wait for the red text to start appearing:
It's failing, which means it's working

Find additional details in the documentation. Or, see how it works in the video below:

Available Free for all WireMock Users.

Want to inject some much-needed chaos into your testing? Try it yourself with any WireMock Cloud account (free or paid); or get in touch if you want our experts to show you around.

/

Latest posts

Have More Questions?