Verify peer cutoff while real owner commands and snapshots are pending
This commit is contained in:
1 parent
5c309b2a9f
commit
6cc59b4ef5
2 files changed
+93
No files matched your search
@@ -189,6 +189,8 @@ struct LanTests : Void::Testing::Suite<LanTests> {
|
||||
[[= Void::Testing::tag("lan-owner")]] Test test_runtime_host_rejects_nondefault_rules_and_faults();
|
||||
[[= Void::Testing::tag("lan-owner")]] Test test_legacy_custody_refuses_handshake_and_preserves_modern_owner();
|
||||
[[= Void::Testing::tag("lan-owner")]] Test test_standalone_custody_discards_queued_snapshot_and_command();
|
||||
[[= Void::Testing::tag("lan-owner")]] Test test_runtime_custody_cuts_off_queued_guest_but_settles_admitted_work();
|
||||
[[= Void::Testing::tag("lan-owner")]] Test test_runtime_custody_discards_queued_snapshot_before_admission();
|
||||
};
|
||||
|
||||
Test LanTests::test_protocol_11_fixed_messages() {
|
||||
@@ -719,4 +721,93 @@ Test LanTests::test_standalone_custody_discards_queued_snapshot_and_command() {
|
||||
require(next.receipts.front().status == CommandStatus::Accepted);
|
||||
}
|
||||
|
||||
Test LanTests::test_runtime_custody_cuts_off_queued_guest_but_settles_admitted_work() {
|
||||
CaptureGate gate;
|
||||
RuntimeOptions options{.ticking = false};
|
||||
options.observer = [&](RuntimePhase phase) { gate.capture(phase); };
|
||||
auto initial = colony_checkpoint();
|
||||
initial.world = mixed_delivery();
|
||||
const auto production = initial.world->production_orders().front().id;
|
||||
const auto resident = initial.world->agents().front().id;
|
||||
SimulationRuntime runtime(std::move(initial), options);
|
||||
auto release = Void::Scope::on_exit([&] { gate.release(); });
|
||||
LanSession host;
|
||||
host.host(0, true);
|
||||
RawGuest guest(host.port(), std::stoull(host.join_code(), nullptr, 16));
|
||||
const auto pump = [&] { host.poll_host(runtime); guest.poll(); };
|
||||
pump_until(pump, [&] { return guest.snapshot != nullptr; }, "Custody guest did not join.");
|
||||
const auto before = runtime.latest();
|
||||
const auto id = before->identity;
|
||||
const CommandPayload accepted{CommandKind::AssignProfession, {},
|
||||
static_cast<std::uint8_t>(Profession::Miner), {}, resident};
|
||||
gate.arm();
|
||||
guest.command(1, accepted.kind, {}, accepted.value, resident);
|
||||
pump_until(pump, [&] { return gate.waiting(); }, "Guest work did not reach blocked capture.");
|
||||
auto canceled = runtime.try_submit({1}, {command_envelope_version, id.world, id.session, id.city,
|
||||
before->next_requests[0], CancelProductionPayload{production}});
|
||||
require(canceled.admission == RuntimeAdmission::Accepted);
|
||||
// This later wire intent is already in TCP when cancellation publishes.
|
||||
guest.command(2, CommandKind::AssignProfession, {}, static_cast<std::uint8_t>(Profession::Builder), resident);
|
||||
guest.poll();
|
||||
gate.release();
|
||||
require(canceled.completion.wait_for(3s) == std::future_status::ready);
|
||||
require(canceled.completion.get().receipt->command_status == CommandStatus::Accepted);
|
||||
require(runtime.latest()->identity.session == id.session && !runtime.latest()->world->legacy_representable());
|
||||
pump_until(pump, [&] { return guest.closed; }, "Incompatible runtime guest stayed connected.");
|
||||
require(host.state() == LanState::Hosting && runtime.view().state == RuntimeState::Running);
|
||||
require(guest.receipts.empty());
|
||||
const auto current = runtime.latest();
|
||||
require(current->next_requests[1] == 2 && current->world->next_command_sequence(2) == 2);
|
||||
require(current->world->agents().front().profession == Profession::Miner);
|
||||
const auto retained = runtime.lookup({2}, {command_envelope_version, id.world, id.session, id.city,
|
||||
before->next_requests[1], accepted});
|
||||
require(retained && retained->status == DispatchStatus::Completed && retained->command_status == CommandStatus::Accepted);
|
||||
require(encode_checkpoint(*current->world, id.world, id.city, *current->rules).has_value());
|
||||
|
||||
// A later compatible incarnation can reconnect; neither the retained work
|
||||
// nor its old socket's reply leaks into the new connection.
|
||||
auto ticket = runtime.begin_load();
|
||||
require(ticket.has_value());
|
||||
auto replacement = colony_checkpoint();
|
||||
auto installed = runtime.try_install(*ticket, replacement);
|
||||
require(installed.admission == RuntimeAdmission::Accepted && installed.completion.wait_for(3s) == std::future_status::ready);
|
||||
require(installed.completion.get().outcome == RuntimeOutcome::Completed);
|
||||
RawGuest next(host.port(), std::stoull(host.join_code(), nullptr, 16));
|
||||
pump_until([&] { host.poll_host(runtime); next.poll(); },
|
||||
[&] { return next.snapshot != nullptr; }, "Guest could not reconnect after custody cutoff.");
|
||||
require(next.receipts.empty() && next.snapshot->next_command_sequence(2) == 1);
|
||||
}
|
||||
|
||||
Test LanTests::test_runtime_custody_discards_queued_snapshot_before_admission() {
|
||||
auto initial = colony_checkpoint();
|
||||
initial.world = mixed_delivery();
|
||||
const auto production = initial.world->production_orders().front().id;
|
||||
const auto resident = initial.world->agents().front().id;
|
||||
for (int job = 0; job < 4096; ++job) static_cast<void>(initial.world->add_job({20, 20}, 1));
|
||||
SimulationRuntime runtime(std::move(initial), {.ticking = false});
|
||||
LanSession host;
|
||||
host.host(0, true);
|
||||
RawGuest guest(host.port(), std::stoull(host.join_code(), nullptr, 16));
|
||||
guest.poll();
|
||||
pump_until([&] { host.poll_host(runtime); }, [&] { return host.state() == LanState::HostConnected; },
|
||||
"Queued-snapshot guest did not authenticate.");
|
||||
guest.poll();
|
||||
require(!guest.input.empty() && !guest.snapshot);
|
||||
const auto partial = guest.input.size();
|
||||
const auto before = runtime.latest();
|
||||
const auto id = before->identity;
|
||||
auto canceled = runtime.try_submit({1}, {command_envelope_version, id.world, id.session, id.city,
|
||||
before->next_requests[0], CancelProductionPayload{production}});
|
||||
require(canceled.admission == RuntimeAdmission::Accepted && canceled.completion.wait_for(3s) == std::future_status::ready);
|
||||
require(canceled.completion.get().receipt->command_status == CommandStatus::Accepted);
|
||||
guest.command(1, CommandKind::AssignProfession, {}, static_cast<std::uint8_t>(Profession::Miner), resident);
|
||||
guest.poll();
|
||||
pump_until([&] { host.poll_host(runtime); guest.poll(); }, [&] { return guest.closed; },
|
||||
"Guest receiving queued snapshot was not dropped.");
|
||||
require(runtime.latest()->identity.session == id.session && !runtime.latest()->world->legacy_representable());
|
||||
require(runtime.view().state == RuntimeState::Running && host.state() == LanState::Hosting);
|
||||
require(guest.input.size() == partial && !guest.snapshot && guest.receipts.empty());
|
||||
require(runtime.latest()->next_requests[1] == 1 && runtime.latest()->world->next_command_sequence(2) == 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in new issue
Block a user