Bound engineering UI state and session events for M9.8b
This commit is contained in:
@@ -186,6 +186,9 @@ void native_input() {
|
||||
key(SDL_SCANCODE_W, true);
|
||||
CHECK(app->poll_events());
|
||||
app->set_ui_capture(true);
|
||||
key(SDL_SCANCODE_TAB, true); // Legacy shortcut cannot escape an external modal.
|
||||
key(SDL_SCANCODE_W, true);
|
||||
CHECK(app->poll_events() && app->ui_captured());
|
||||
CHECK(required(app->sample_intention(43)).move_y == 0);
|
||||
key(SDL_SCANCODE_W, true);
|
||||
CHECK(app->poll_events());
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "evo/client/ui_state.hpp"
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
using namespace evo::client;
|
||||
void check(bool ok) {
|
||||
if (!ok)
|
||||
throw std::runtime_error("UI state contract");
|
||||
}
|
||||
int main() try {
|
||||
UiState ui;
|
||||
check(ui.advance(100).has_value());
|
||||
auto first = ui.notify("Connected", NoticeLevel::info, 10);
|
||||
check(first.has_value());
|
||||
check(ui.advance(109).has_value() && ui.notices().size() == 1);
|
||||
check(ui.advance(110).has_value() && ui.notices().empty());
|
||||
check(!ui.dismiss(*first));
|
||||
check(!ui.advance(109));
|
||||
check(!ui.notify(std::string(241, 'x'), NoticeLevel::info));
|
||||
check(!ui.notify(std::string_view{"x\0y", 3}, NoticeLevel::info));
|
||||
check(!ui.notify("invalid", NoticeLevel::info, 0));
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
check(ui.notify("Burst", NoticeLevel::warning).has_value());
|
||||
check(ui.notices().size() == 8 && ui.evicted_notices() == 9992);
|
||||
auto dismissed = ui.notices().back().id;
|
||||
check(ui.dismiss(dismissed));
|
||||
check(ui.notices().size() == 7 && !ui.dismiss(dismissed));
|
||||
auto dialog = ui.open_dialog("Disconnect?", "Current intentions may remain unknown.");
|
||||
check(dialog.has_value());
|
||||
check(!ui.open_dialog("Other", "Blocked"));
|
||||
check(!ui.close_dialog(*dialog + 1));
|
||||
check(ui.close_dialog(*dialog));
|
||||
auto next = ui.open_dialog("New", "New modal");
|
||||
check(next.has_value());
|
||||
check(!ui.close_dialog(*dialog) && ui.dialog().has_value());
|
||||
check(ui.close_dialog(*next));
|
||||
check(ui.advance(std::numeric_limits<std::uint64_t>::max()).has_value());
|
||||
check(!ui.notify("Overflow", NoticeLevel::error, 1));
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
}
|
||||
@@ -662,9 +662,42 @@ void liveness() {
|
||||
CHECK(h.until([&] { return again->phase() == SessionPhase::established; }));
|
||||
}
|
||||
}
|
||||
void event_backpressure() {
|
||||
Harness h;
|
||||
h.tick();
|
||||
auto c = h.client(grants(7, 3, 100));
|
||||
CHECK(h.until([&] { return c->latest_view().has_value(); }));
|
||||
std::uint64_t sent = 0;
|
||||
CHECK(h.until([&] {
|
||||
if (c->phase() != SessionPhase::established)
|
||||
return true;
|
||||
// Invalid vector: final rejection frees outstanding capacity, but the host
|
||||
// intentionally never drains its event queue throughout this burst.
|
||||
for (int batch = 0; batch < 16; ++batch)
|
||||
if (c->send({sent + 1, 0, 1000, 1000}))
|
||||
++sent;
|
||||
return false;
|
||||
}));
|
||||
CHECK(c->phase() == SessionPhase::backoff);
|
||||
const auto remaining = c->grants_left();
|
||||
for (int i = 0; i < 100; ++i)
|
||||
c->poll(Clock::now() + std::chrono::seconds{60});
|
||||
CHECK(c->grants_left() == remaining && c->phase() == SessionPhase::backoff);
|
||||
CHECK(c->environment().freshness() == client::Freshness::stale);
|
||||
const auto events = c->take_events();
|
||||
CHECK(events.size() <= SessionClient::max_events);
|
||||
CHECK(has(events, ClientEvent::Kind::backpressure) && has(events, ClientEvent::Kind::lost));
|
||||
const auto accounted = std::ranges::count_if(events, [](const ClientEvent& e) {
|
||||
return e.kind == ClientEvent::Kind::result || e.kind == ClientEvent::Kind::unknown;
|
||||
});
|
||||
CHECK(static_cast<std::uint64_t>(accounted) == sent);
|
||||
CHECK(h.until([&] { return c->latest_view().has_value(); }));
|
||||
CHECK(c->phase() == SessionPhase::established);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void session_tests() {
|
||||
event_backpressure();
|
||||
ledger_exclusive_owner();
|
||||
ledger_incomplete_records();
|
||||
connect_view_intents_and_outcomes();
|
||||
|
||||
Reference in New Issue
Block a user