// Route: /operability/breaker (closed -> open -> half-open -> closed) #include "support/Assert.hpp" using namespace molo::example::test; using molo::example::fw::Method; static const char* kForm = "application/x-www-form-urlencoded"; int main() { Fixture f; auto page = f.client->get("/operability/breaker"); check(page.status == 200, "status 200"); check(contains(page.headers.get("Content-Type"), "text/html"), "html"); check(contains(page.body, "closed"), "starts closed"); for (int i = 0; i < 3; ++i) f.client->post("/operability/breaker/failure", "", kForm); check(contains(f.client->get("/operability/breaker").body, ">open<"), "three failures open it"); auto rej = f.client->post("/operability/breaker/success", "", kForm); check(contains(rej.body, "rejected: breaker open"), "call rejected while open"); for (int i = 0; i < 3; ++i) f.client->post("/operability/breaker/tick", "", kForm); check(contains(f.client->get("/operability/breaker").body, ">half-open<"), "30 s later half-open"); f.client->post("/operability/breaker/success", "", kForm); check(contains(f.client->get("/operability/breaker").body, ">closed<"), "good probe closes"); auto json = f.client->request(Method::Post, "/operability/breaker/failure", "", {{"Accept", "application/json"}}); check(json.status == 200 && contains(json.body, "\"name\":\"breaker\""), "json client gets state"); check(f.client->request(Method::Delete, "/operability/breaker").status == 405, "405 on delete"); check(contains(f.client->get("/operability/debug").body, "\"breaker\""), "side effect: debug snapshot lists it"); return finish("operability/breaker"); }