feat(workflow): example covers security, platform, enterprise and resilience features
105 route tests, matrix crawl, spec and README updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// 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");
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Route: /operability/bulkhead (2 slots, queue of 1, then reject)
|
||||
#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;
|
||||
check(f.client->get("/operability/bulkhead").status == 200, "status 200");
|
||||
auto a = f.client->post("/operability/bulkhead/acquire", "", kForm);
|
||||
check(contains(a.body, ">admitted<") || contains(a.body, "admitted"), "first admitted");
|
||||
f.client->post("/operability/bulkhead/acquire", "", kForm);
|
||||
auto q = f.client->post("/operability/bulkhead/acquire", "", kForm);
|
||||
check(contains(q.body, "queued"), "third queued");
|
||||
auto r = f.client->post("/operability/bulkhead/acquire", "", kForm);
|
||||
check(contains(r.body, "rejected: compartment full"), "fourth rejected (limit)");
|
||||
check(contains(r.body, "2/2"), "side effect: active slots full");
|
||||
check(f.client->post("/operability/bulkhead/nope", "", kForm).status == 404, "404 unknown action");
|
||||
for (int i = 0; i < 3; ++i) f.client->post("/operability/bulkhead/release", "", kForm);
|
||||
check(contains(f.client->post("/operability/bulkhead/release", "", kForm).body, "nothing to release"), "empty release is reported");
|
||||
return finish("operability/bulkhead");
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Route: /operability/chaos (dry run default, hard blast radius)
|
||||
#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;
|
||||
check(f.client->get("/operability/chaos").status == 200, "status 200");
|
||||
auto dry = f.client->post("/operability/chaos/run", "percent=40&max_faults=3", kForm);
|
||||
check(contains(dry.body, "dry run: 0 injected, 3 planned"), "default is a dry run");
|
||||
auto armed = f.client->post("/operability/chaos/run", "percent=40&max_faults=2&armed=1", kForm);
|
||||
check(contains(armed.body, "armed: 2 injected, 2 planned"), "armed run capped at max_faults");
|
||||
auto big = f.client->post("/operability/chaos/run", "percent=90&max_faults=9", kForm);
|
||||
check(big.status == 422 && contains(big.body, "must be between 0 and 50"), "percent above cap rejected");
|
||||
check(contains(big.body, "must be between 1 and 5"), "faults above cap rejected");
|
||||
check(contains(f.client->get("/operability/chaos").body, "total_injected"), "side effect: totals tracked");
|
||||
check(contains(f.client->get("/operability/chaos").body, ">2<"), "only the armed run injected");
|
||||
return finish("operability/chaos");
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Route: /operability/coord (lease, election, lock with fencing tokens)
|
||||
#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;
|
||||
check(f.client->get("/operability/coord").status == 200, "status 200");
|
||||
auto a = f.client->post("/operability/coord/acquire", "key=lock&owner=a", kForm);
|
||||
check(contains(a.body, "granted token 1"), "a gets token 1");
|
||||
auto b = f.client->post("/operability/coord/acquire", "key=lock&owner=b", kForm);
|
||||
check(contains(b.body, "denied, held by a"), "b denied while lease live");
|
||||
f.client->post("/operability/coord/tick", "", kForm);
|
||||
f.client->post("/operability/coord/tick", "", kForm);
|
||||
auto b2 = f.client->post("/operability/coord/acquire", "key=lock&owner=b", kForm);
|
||||
check(contains(b2.body, "granted token 2"), "b gets token 2 after expiry");
|
||||
check(contains(f.client->post("/operability/coord/write", "key=lock&token=2", kForm).body, "write accepted"), "fresh token writes");
|
||||
auto stale = f.client->post("/operability/coord/write", "key=lock&token=1", kForm);
|
||||
check(contains(stale.body, "stale fencing token"), "stale token fenced off");
|
||||
auto bad = f.client->post("/operability/coord/acquire", "key=db&owner=a", kForm);
|
||||
check(bad.status == 422, "422 unknown key");
|
||||
check(contains(f.client->post("/operability/coord/acquire", "key=leader&owner=n1", kForm).body, "granted"), "election via leader key");
|
||||
check(contains(f.client->get("/operability/coord").body, "held by b"), "side effect: holder shown");
|
||||
return finish("operability/coord");
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Route: /operability/deadline (budget shared across hops)
|
||||
#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;
|
||||
check(f.client->get("/operability/deadline").status == 200, "status 200");
|
||||
auto ok = f.client->post("/operability/deadline/run", "budget_ms=100&hops=3", kForm);
|
||||
check(contains(ok.body, "all hops finished in budget"), "fits in budget");
|
||||
auto late = f.client->post("/operability/deadline/run", "budget_ms=70&hops=5", kForm);
|
||||
check(contains(late.body, "deadline exceeded at hop 3"), "expires at hop 3");
|
||||
check(contains(late.body, "call skipped"), "side effect: log shows skipped hop");
|
||||
auto bad = f.client->post("/operability/deadline/run", "budget_ms=99999&hops=0", kForm);
|
||||
check(bad.status == 422 && contains(bad.body, "must be between 0 and 5000"), "422 limit on budget");
|
||||
auto json = f.client->request(Method::Post, "/operability/deadline/run", "{\"budget_ms\":\"abc\"}", {{"Content-Type", "application/json"}});
|
||||
check(json.status == 422 && contains(json.headers.get("Content-Type"), "json"), "json client gets json error");
|
||||
return finish("operability/deadline");
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Route: /operability/debug (snapshot of every lab)
|
||||
#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;
|
||||
f.client->post("/operability/slo/bad", "", kForm);
|
||||
auto res = f.client->get("/operability/debug");
|
||||
check(res.status == 200, "status 200");
|
||||
check(contains(res.headers.get("Content-Type"), "application/json"), "json");
|
||||
check(contains(res.body, "\"labs\""), "labs object");
|
||||
for (const char* n : {"breaker", "bulkhead", "shedder", "deadline", "slo", "chaos", "deploy", "coord", "supplychain", "client-retry", "client-session", "migrations", "transaction", "query", "singleflight", "ttl"})
|
||||
check(contains(res.body, std::string("\"") + n + "\":{"), std::string("lab present: ") + n);
|
||||
check(contains(res.body, "bad event"), "side effect: earlier action visible in log");
|
||||
check(f.client->post("/operability/debug", "", kForm).status == 405, "405 on post");
|
||||
return finish("operability/debug");
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Route: /operability/deploy (rolling, blue-green, rollback)
|
||||
#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;
|
||||
check(f.client->get("/operability/deploy").status == 200, "status 200");
|
||||
f.client->post("/operability/deploy/start", "strategy=rolling&version=v2", kForm);
|
||||
f.client->post("/operability/deploy/step", "", kForm);
|
||||
check(contains(f.client->get("/operability/deploy").body, "v2,v1,v1,v1"), "one instance replaced");
|
||||
auto again = f.client->post("/operability/deploy/start", "strategy=rolling", kForm);
|
||||
check(contains(again.body, "already in progress"), "second rollout refused");
|
||||
auto rb = f.client->post("/operability/deploy/rollback", "", kForm);
|
||||
check(contains(rb.body, "v1,v1,v1,v1") && contains(rb.body, "rolled back"), "rollback restores fleet");
|
||||
f.client->post("/operability/deploy/start", "strategy=bluegreen&version=v3", kForm);
|
||||
f.client->post("/operability/deploy/step", "", kForm);
|
||||
check(contains(f.client->get("/operability/deploy").body, "v1,v1,v1,v1"), "green prepared, blue serves");
|
||||
f.client->post("/operability/deploy/step", "", kForm);
|
||||
auto done = f.client->get("/operability/deploy");
|
||||
check(contains(done.body, "v3,v3,v3,v3") && contains(done.body, "done"), "switched");
|
||||
auto bad = f.client->post("/operability/deploy/start", "strategy=canary", kForm);
|
||||
check(bad.status == 422 && contains(bad.body, "must be one of: rolling, bluegreen"), "422 unknown strategy");
|
||||
return finish("operability/deploy");
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Route: /operability/shedder (low priority shed first)
|
||||
#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;
|
||||
check(f.client->get("/operability/shedder").status == 200, "status 200");
|
||||
f.client->post("/operability/shedder/enter", "priority=low", kForm);
|
||||
f.client->post("/operability/shedder/enter", "priority=low", kForm);
|
||||
auto low = f.client->post("/operability/shedder/enter", "priority=low", kForm);
|
||||
check(contains(low.body, "shed"), "third low request shed");
|
||||
auto high = f.client->post("/operability/shedder/enter", "priority=high", kForm);
|
||||
check(contains(high.body, "accepted"), "high priority still accepted");
|
||||
auto bad = f.client->post("/operability/shedder/enter", "priority=urgent", kForm);
|
||||
check(bad.status == 422 && contains(bad.body, "must be one of: low, high"), "422 inline error");
|
||||
check(!contains(bad.body, "{\"errors\""), "no raw json in page");
|
||||
check(contains(f.client->get("/operability/shedder").body, "3/3"), "side effect: inflight 3/3");
|
||||
return finish("operability/shedder");
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Route: /operability/slo (error budget burn)
|
||||
#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;
|
||||
check(f.client->get("/operability/slo").status == 200, "status 200");
|
||||
for (int i = 0; i < 20; ++i) f.client->post("/operability/slo/good", "", kForm);
|
||||
check(contains(f.client->get("/operability/slo").body, "healthy"), "healthy without bad events");
|
||||
f.client->post("/operability/slo/bad", "", kForm);
|
||||
check(contains(f.client->get("/operability/slo").body, "burning"), "one bad of 21 is within budget");
|
||||
f.client->post("/operability/slo/bad", "", kForm);
|
||||
f.client->post("/operability/slo/bad", "", kForm);
|
||||
check(contains(f.client->get("/operability/slo").body, "exhausted"), "budget exhausted");
|
||||
f.client->post("/operability/slo/reset", "", kForm);
|
||||
check(contains(f.client->get("/operability/slo").body, "0/100"), "side effect: window emptied");
|
||||
for (int i = 0; i < 105; ++i) f.client->request(Method::Post, "/operability/slo/good", "", {{"Accept", "application/json"}});
|
||||
check(contains(f.client->get("/operability/slo").body, "100/100"), "limit: window capped at 100");
|
||||
check(f.client->request(Method::Put, "/operability/slo").status == 405, "405 on put");
|
||||
return finish("operability/slo");
|
||||
}
|
||||
Reference in New Issue
Block a user