Allow four-hour dev session windows
Foundation / checks (client) (push) Successful in 12m45s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (network) (push) Successful in 9m59s
Foundation / checks (postgres) (push) Successful in 39m8s
Foundation / checks (tsan) (push) Successful in 7m57s
Foundation / checks (checks) (push) Failing after 10m55s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-05 12:50:50 -04:00
parent 77aadda983
commit c19d9c0e71
3 changed files with 46 additions and 31 deletions
+37 -23
View File
@@ -1,42 +1,56 @@
#include "evo/server/session_window.hpp"
#include <cassert>
#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 == 4 * 60 * 60);
auto opened = SessionWindow::open("dev-42:1200", now);
assert(opened.has_value());
assert(opened->activation_id() == "dev-42");
assert(opened->deadline_seconds() == 1200);
assert(opened->accepting(1'199));
assert(!opened->accepting(1'200));
assert(opened->closed());
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);
assert(restarted.has_value());
assert(restarted->deadline_seconds() == 1200);
assert(!SessionWindow::open("dev-42:1200", 1'200).has_value());
assert(!SessionWindow::open("dev-42:1200", 1'201).has_value());
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.
assert(!SessionWindow::open("dev-43:1200", 1'300).has_value());
assert(restarted->accepting(1'150));
assert(restarted->accepting(1'050));
assert(!restarted->accepting(1'200));
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 excessive windows fail closed.
assert(!SessionWindow::open(":1200", now).has_value());
assert(!SessionWindow::open("dev space:1200", now).has_value());
assert(!SessionWindow::open("dev-44:not-a-number", now).has_value());
assert(!SessionWindow::open("dev-45:3001", now).has_value());
// 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-46:1200", now);
assert(close.has_value());
auto close = SessionWindow::open("dev-47:1200", now);
CHECK(close.has_value());
close->close();
assert(!close->accepting(1'001));
CHECK(!close->accepting(1'001));
return 0;
}