Blog

Chaos on mocks: test app resilience before the backend exists

Apps get built before their servers, on mocks. Mocks answer instantly and always correctly, so error screens, timeouts and retries meet a bad network for the first time on the real backend, a week before release. Chaos in Microkoi Bench works on mock responses too: proxy mocks and mock servers start lagging, failing and dropping connections by your rules. You test resilience on day one, not on the last day.

Why a perfect mock does harm

A mock answers in milliseconds and never fails. A screen built on it has never seen a slow response. The loading indicator flashes for a single frame, the error branch has never run, and no timeout is set.

You can give a mock a delay and an error response, but they are constant: every request gets the error. Real life works differently — failures are rare and mixed in with successes. That mix is exactly what chaos gives you.

Two places where chaos works

Where the response comes fromWhose chaos profileWhere you see the failures
Proxy mockThe active “Traffic” profileThe first column of the “Traffic” table
Mock serverEach server’s own profileThe server’s “Request log” tab

How a proxy mock differs from a mock server, and when to pick which, is covered in “Mock server or proxy mock: which one to use for testing”. This one is about what changes when you add chaos to them.

Mock server: its own profile and its own switch

Take a restaurant table booking app. There is no backend, only two mock servers: “Restaurants” returns the list and the menus, “Bookings” accepts a table reservation. How to build a server like that is covered in “API mock server: build a mobile app before the backend is ready”.

  1. Open the “Mock servers” section and select the “Bookings” server.
  2. In the chaos row to the right of “Network access”, click “Create profile…” if you have no profiles, or pick one from the “Choose profile” list. The profile active in “Traffic” is marked with a dot.
  3. Click “⋯” → “Edit profile…”. The “Chaos” window opens on this server’s profile. The active “Traffic” profile stays the same.
  4. Click “Add rule” and set the method to POST and the path to /v1/bookings. A new rule starts turned off so it doesn’t slow everything down at once: turn it on.
  5. Turn off the “Delay” block, turn on “Errors” with a 20% probability, codes 503 and 500, and “When” set to “After server”. Click “Done”.
  6. Go back to the server and click “Chaos”. The chaos row turns orange, and a “Chaos · 1 server” badge appears in the window title bar.

Now roughly every fifth booking gets an error, even though the endpoint has prepared its response. This is how you check that “Retry” doesn’t create a second booking — the check that is hardest to set up on a real backend.

Meanwhile the “Restaurants” server answers steadily. Each server has its own profile and its own “Chaos” button, independent of each other and of “Traffic”. Server rules match requests by method and path; the host in a rule is ignored.

What the app gets from a mock server

FailureWhat the app gets
DelayThe request delay, then the endpoint’s delay, then the response delay
Errors, before serverThe code from the rule instead of the endpoint’s response
Errors, after serverThe response is ready, but an error arrives
DropThe connection drops, not a single byte of response
HangSilence until the app times out or the rule’s limit runs out
Cut bodyThe endpoint’s status, headers and half of the body
SpeedThe response at the speed of the chosen network

A chaos error is short, with a body like “Microkoi Bench chaos: 503 Service Unavailable”, and for 429 and 503 it carries a Retry-After header if the rule sets one.

The mock server log with failures

In the “Request log” tab, requests hit by chaos have an orange lightning bolt before the address. Its tooltip says what was done and names the rule, the profile and the request number in the run.

  • Chaos error — the status is in the chaos color and the endpoint name stays: it matched, but Bench answered instead.
  • Drop and hang — “drop” or “hang” instead of a status.
  • Cut body — the endpoint’s status in the chaos color.
  • Delay or slow network only — the endpoint’s real status in the regular color.
  • The app didn’t wait for the response — the row is marked “canceled”, and the bolt stays.

The log shows how many times the app retried the booking after an error, and with what pause.

Proxy mock: chaos on top of a mock

Proxy mocks follow the active “Traffic” profile. To chaos, a mock is the server. “Before server” answers with an error or drops the connection instead of the mock, and “After server” spoils the mock’s finished response.

With no backend, almost every response in “Traffic” comes from a mock. When you dig into one, the question is: did the mock answer that way itself, or did chaos spoil it? An error in a mock means fixing the mock; a chaos failure is a test of the app. The answer is in the narrow first column of the table, where Bench marks who answered the request.

IconWhat happened
Blue cubeA mock answered, chaos left it alone
Orange bolt in a blue squareA mock answered, and chaos spoiled or delayed it
Orange boltChaos on the server response, no mock involved

A bolt on a blue background is one icon for two facts: the background comes from the mock, the bolt from chaos. The icon’s tooltip has two lines. The first names the mock: Mocked by “Restaurant list”. The second says what chaos did, with the moment named relative to the mock: “Chaos on top of the mock: 503 from Bench chaos · after mock”.

If chaos answered with an error instead of the mock, the status is in the chaos color. The toggle above the response in the exchange panel reads “Bench 503 / Mock 200”: it shows both what the app received and what the mock answered.

“Chaos” in the “Show only” group of “Filters” keeps exchanges with a bolt in the list, including those on a blue background. “Without chaos” removes them, leaving the mock responses as they are. All the icons in that column are explained in “Chaos engineering for a mobile app: where to start”.

The mock’s delay and chaos delays add up. Set a fixed delay in the mock itself and a random one in the chaos rule.

Good to know up front

  • Every time Bench starts or a workspace opens, chaos is off on all servers. The selected profile is kept: just click “Chaos” again.
  • The “Turn off” cross on the title bar badge turns chaos off everywhere: in “Traffic” and on all mock servers.
  • Chaos profiles live in the workspace’s chaos/ folder and go to git. Which profile a server uses is stored on this computer.
  • A mock server doesn’t apply chaos to requests with no matching endpoint or to CORS preflight requests.
  • The bench-mocks program for continuous integration has no chaos: it works only in the Bench app.

Once the backend is up, you can make the same profile active in “Traffic” and run the same check against the real server.

Turn chaos on for the mock server you’re working with right now, and write to beta@microkoi.com about what your app survived and what it didn’t. We read every email.

Microkoi BenchChaosDelays, errors and a slow network

Try it on your own project

The beta is free and needs no sign-up. Download it, pick your project folder and start the proxy — your first requests will show up within minutes.

Version 0.9.6 · macOS, Windows and Linux · no sign-up