29 lines
1.6 KiB
C++
29 lines
1.6 KiB
C++
// 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");
|
||
|
|
}
|