Files
aevolution/tests/session_window_tests.cpp
T
dingo bb703889c5
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (tsan) (push) Successful in 7m53s
Foundation / checks (checks) (push) Successful in 32m22s
Foundation / checks (postgres) (push) Successful in 39m30s
Foundation / server-image (push) Successful in 6s
Foundation / postgres-tools (push) Successful in 16s
Foundation / image (push) Successful in 2m32s
Fix session window test warning
2026-10-05 14:09:50 -04:00

57 lines
2.6 KiB
C++

#include "evo/server/session_window.hpp"
#include <cstdio>
#include <string>
using evo::server::SessionWindow;
#define CHECK(...) \
do { \
if (!(__VA_ARGS__)) { \
std::fprintf(stderr, "CHECK failed: %s at line %d\n", #__VA_ARGS__, __LINE__); \
return 1; \
} \
} while (false)
int main() {
constexpr std::uint64_t now = 1'000;
static_assert(SessionWindow::max_duration_seconds == std::uint64_t{14'400});
auto opened = SessionWindow::open("dev-42:1200", now);
CHECK(opened.has_value());
CHECK(opened->activation_id() == "dev-42");
CHECK(opened->deadline_seconds() == 1200);
CHECK(opened->accepting(1'199));
CHECK(!opened->accepting(1'200));
CHECK(opened->closed());
// A restart re-reads the same absolute deadline; it does not get a new duration.
auto restarted = SessionWindow::open("dev-42:1200", 1'100);
CHECK(restarted.has_value());
CHECK(restarted->deadline_seconds() == 1200);
CHECK(!SessionWindow::open("dev-42:1200", 1'200).has_value());
CHECK(!SessionWindow::open("dev-42:1200", 1'201).has_value());
// Delayed application and clock movement cannot extend an expired window.
CHECK(!SessionWindow::open("dev-43:1200", 1'300).has_value());
CHECK(restarted->accepting(1'150));
CHECK(restarted->accepting(1'050));
CHECK(!restarted->accepting(1'200));
// Invalid activation/deadline forms and windows over four hours fail closed.
CHECK(!SessionWindow::open(":1200", now).has_value());
CHECK(!SessionWindow::open("dev space:1200", now).has_value());
CHECK(!SessionWindow::open("dev-44:not-a-number", now).has_value());
const auto maximum_deadline = now + SessionWindow::max_duration_seconds;
const auto maximum_window =
SessionWindow::open("dev-45:" + std::to_string(maximum_deadline), now);
CHECK(maximum_window.has_value());
CHECK(maximum_window->deadline_seconds() == maximum_deadline);
CHECK(!SessionWindow::open("dev-46:" + std::to_string(maximum_deadline + 1), now).has_value());
auto close = SessionWindow::open("dev-47:1200", now);
CHECK(close.has_value());
close->close();
CHECK(!close->accepting(1'001));
return 0;
}