Files
moloapp/tests/example/data/singleflight_test.cpp
T
retoorandClaude Sonnet 5.5 62fdd08da8 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>
2026-10-24 02:19:52 +02:00

23 lines
1.1 KiB
C++

// Route: /data/singleflight (concurrent loads collapse into one)
#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("/data/singleflight").status == 200, "status 200");
auto res = f.client->post("/data/singleflight/run", "callers=8", kForm);
check(contains(res.body, "8 callers, 1 load(s)"), "eight callers share one load");
auto one = f.client->post("/data/singleflight/run", "callers=1", kForm);
check(contains(one.body, "1 callers, 1 load(s)"), "single caller loads once");
auto max = f.client->post("/data/singleflight/run", "callers=16", kForm);
check(contains(max.body, "16 callers, 1 load(s)"), "cap of 16 threads still collapses");
auto bad = f.client->post("/data/singleflight/run", "callers=17", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 16"), "422 above thread cap");
check(contains(f.client->get("/data/singleflight").body, ">3<"), "side effect: three runs counted");
return finish("data/singleflight");
}