Два своих сервиса на стандартной библиотеке: orders вызывает inventory по HTTP через прокси, который вносит сбои — задержку, 500, обрыв соединения, «чёрную дыру». Тесты проверяют и то, что увидел пользователь, и то, что на самом деле произошло на складе.
Two services of our own on the standard library: orders calls inventory over HTTP through a proxy that injects faults: latency, 500s, dropped connections, a black hole. The tests check what the user saw and what really happened in inventory.
Выберите сбой, который прокси внесёт между сервисами. Таймаут попытки 150 мс, попыток 3. Переключатель ниже убирает Idempotency-Key — это посаженный баг M1: пользователь всё так же получает 201, но склад списывает дважды.
Pick the fault the proxy injects between the services. Timeout per attempt 150 ms, 3 attempts. The switch below drops the Idempotency-Key: planted bug M1. The user still gets 201, but inventory reserves twice.
Порог — 5 неудач подряд, пауза — 30 с. В тестах время двигает поддельные часы, поэтому тест на «через 30 секунд» идёт миллисекунды. Нажимайте кнопки.
Threshold: 5 failures in a row; cool-down: 30 s. In the tests a fake clock moves time, so "after 30 seconds" takes milliseconds. Press the buttons.
go run scripts/mutants.go сажает по одному багу и запускает go test -race ./....
go run scripts/mutants.go plants one bug at a time and runs go test -race ./....