ADR-0066: evo-server --ops-listen serves /livez (loop responding, never authority), /readyz (200 only while the host holds the lease with a verified recovered head) and /metrics (Prometheus text: 30 fixed series for readiness, phase, lease epoch/remaining, simulated/committed ticks, commit lag, checkpoint age, tick debt, queue use and bounds, and counters; the only labels are a 6-value phase and 4-value drop reason). The dependency-free OpsServer runs on the host loop with no thread: GET on exact paths, 405/404/400/431 responses, 8 connections with excess refused on accept, 4 KiB requests, 1 s deadlines, 16 KiB responses. HostStatus/phase types moved to the portable evo::ops library with a Windows-tested renderer. evo-server now refuses to start without its required identity and connection settings. Adds the server-runtime Docker target (evo-server + pinned libpq, UID 10001, no credentials), a CI server-image job with smoke script and optional publishing, and a Kubernetes example outside Argo. Validated: Windows CTest 59/59; Linux Debug/Release/clang-tidy/ASan CTest 59/59; PostgreSQL suites under Release, clang-tidy and ASan with real process probes; two ops mutations caught. Docker build/smoke and Gitea CI not executed locally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
4.2 KiB
C++
96 lines
4.2 KiB
C++
#include "evo/persistence/postgres.hpp"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <source_location>
|
|
#include <stdexcept>
|
|
void run_region_lease_store_tests();
|
|
void run_region_checkpoint_store_tests();
|
|
void run_region_host_tests();
|
|
void run_region_server_process_tests();
|
|
void run_region_recovery_tests();
|
|
void run_region_ops_tests();
|
|
namespace {
|
|
using namespace evo::persistence;
|
|
using namespace std::chrono_literals;
|
|
void check(bool value, std::source_location at = std::source_location::current()) {
|
|
if (!value)
|
|
throw std::runtime_error("PostgreSQL test line " + std::to_string(at.line()));
|
|
}
|
|
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
|
std::string env(const char* key) {
|
|
const auto* value = std::getenv(key);
|
|
if (!value)
|
|
throw std::runtime_error("missing test environment");
|
|
return value;
|
|
}
|
|
void run() {
|
|
PgOptions options{env("PGHOST"), {}, env("PGPORT"), env("PGDATABASE"), env("PGUSER"), {}, {}};
|
|
auto made = Postgres::connect(options, 5s);
|
|
CHECK(made);
|
|
auto db = std::move(*made);
|
|
const std::array<std::string, 1> hostile{"a'); DROP SCHEMA evolution CASCADE; --"};
|
|
auto rows = db->query("SELECT $1::text, NULL::text", hostile, 5s);
|
|
CHECK(rows && rows->size() == 1 && (*rows)[0].size() == 2);
|
|
CHECK((*rows)[0][0] == hostile[0] && !(*rows)[0][1]);
|
|
CHECK(db->query("BEGIN", {}, 5s));
|
|
CHECK(db->query(
|
|
"INSERT INTO evolution.region_leases(world_id,region_id,frame_id) VALUES (1,1,1)", {}, 5s));
|
|
auto duplicate = db->query(
|
|
"INSERT INTO evolution.region_leases(world_id,region_id,frame_id) VALUES (1,1,1)", {}, 5s);
|
|
CHECK(!duplicate && duplicate.error().kind == PgError::sql);
|
|
CHECK(std::string(duplicate.error().sqlstate.data()) == "23505");
|
|
CHECK(db->query("ROLLBACK", {}, 5s));
|
|
rows = db->query("SELECT count(*) FROM evolution.region_leases", {}, 5s);
|
|
CHECK(rows && (*rows)[0][0] == "0");
|
|
for (const auto& value :
|
|
{std::string{"-1"}, std::string{"18446744073709551616"}, std::string{"1.5"}}) {
|
|
const std::array<std::string, 1> parameter{value};
|
|
CHECK(!db->query("SELECT $1::evolution.u64", parameter, 5s));
|
|
}
|
|
rows = db->query("SELECT 18446744073709551615::evolution.u64", {}, 5s);
|
|
CHECK(rows && (*rows)[0][0] == "18446744073709551615");
|
|
CHECK(db->query("SET ROLE evo_runtime_test", {}, 5s));
|
|
auto denied = db->query(
|
|
"INSERT INTO evolution.region_leases(world_id,region_id,frame_id) VALUES (2,2,2)", {}, 5s);
|
|
CHECK(!denied && std::string(denied.error().sqlstate.data()) == "42501");
|
|
CHECK(db->query("RESET ROLE", {}, 5s));
|
|
auto timeout = db->query("SELECT pg_catalog.pg_sleep(2)", {}, 50ms);
|
|
CHECK(!timeout && timeout.error().kind == PgError::unknown);
|
|
auto closed = db->query("SELECT 1", {}, 5s);
|
|
CHECK(!closed && closed.error().kind == PgError::closed);
|
|
made = Postgres::connect(options, 5s);
|
|
CHECK(made);
|
|
auto oversized = (*made)->query("SELECT pg_catalog.generate_series(1,129)", {}, 5s);
|
|
CHECK(!oversized && oversized.error().kind == PgError::unknown);
|
|
made = Postgres::connect(options, 5s);
|
|
CHECK(made);
|
|
auto disconnected = (*made)->query(
|
|
"SELECT pg_catalog.pg_terminate_backend(pg_catalog.pg_backend_pid())", {}, 5s);
|
|
CHECK(!disconnected && disconnected.error().kind == PgError::unknown);
|
|
options.user = "no_such_evo_user";
|
|
CHECK(!Postgres::connect(options, 1s));
|
|
}
|
|
} // namespace
|
|
int main() {
|
|
try {
|
|
run();
|
|
std::puts("postgres adapter integration passed");
|
|
run_region_lease_store_tests();
|
|
std::puts("region lease fencing integration passed");
|
|
run_region_checkpoint_store_tests();
|
|
std::puts("region checkpoint publication integration passed");
|
|
run_region_host_tests();
|
|
std::puts("region host integration passed");
|
|
run_region_server_process_tests();
|
|
std::puts("region server process integration passed");
|
|
run_region_recovery_tests();
|
|
std::puts("region recovery integration passed");
|
|
run_region_ops_tests();
|
|
std::puts("region ops integration passed");
|
|
return 0;
|
|
} catch (const std::exception& e) {
|
|
std::fprintf(stderr, "%s\n", e.what());
|
|
return 1;
|
|
}
|
|
}
|