18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 11:06:03 +01:00

feat(simulation): a real time watchdog ends a test run that hangs

A test run that hung, in the loading or anywhere else, waited until whoever
started it killed it. A watchdog thread now ends a run still going test.wall_timeout
seconds of real time after the start of the simulator, loading included: it says
`test: timeout ... still running after N s of real time` and quits with the
timeout code, whatever the main thread is doing, with no dialog. A test that has
ended but whose simulator doesn't close ends with its own result.

The limit is test.wall_timeout (settings, the scenery's config block) or
--test-wall-timeout, which wins. Not given, it is test.timeout + 600 s: ten
minutes for the loading, and a simulation that runs at least as fast as real
time is never cut short. test.timeout 0 means no watchdog unless the limit is
given; test.wall_timeout 0 turns it off.

run.py passes the case's timeout as --test-wall-timeout and kills a simulator
only 30 s after it. A timeout from the watchdog counts as wall_timeout there, so
a run that hung doesn't pass a case expecting the simulation time to run out;
test_mode_wall_timeout ends while loading on a limit of 2 s.
This commit is contained in:
jerrrrycho
2026-11-08 11:33:36 +01:00
parent 14d25520f3
commit 03a417c7b0
11 changed files with 210 additions and 35 deletions

View File

@@ -80,17 +80,19 @@ TEST_CASE("test mode: the command line")
CHECK_FALSE(commandline.enabled);
CHECK(commandline.error.empty());
}
SUBCASE("--test and its limit, in any order")
SUBCASE("--test and its limits, in any order")
{
auto const commandline{parse({"-s", "td.scn", "--test-timeout", "240", "--test"})};
auto const commandline{parse({"--test-wall-timeout", "900", "-s", "td.scn", "--test", "--test-timeout", "240"})};
CHECK(commandline.enabled);
CHECK(commandline.timeout == 240.0);
CHECK(commandline.wall_timeout == 900.0);
CHECK(commandline.error.empty());
}
SUBCASE("a limit not given stays unset")
{
auto const commandline{parse({"--test", "-s", "td.scn"})};
CHECK_FALSE(commandline.timeout.has_value());
CHECK_FALSE(commandline.wall_timeout.has_value());
}
SUBCASE("a limit which isn't a number is an error, not a limit turned off")
{
@@ -101,12 +103,17 @@ TEST_CASE("test mode: the command line")
}
SUBCASE("a limit without its value is an error")
{
auto const commandline{parse({"--test", "-s", "td.scn", "--test-timeout"})};
auto const commandline{parse({"--test", "-s", "td.scn", "--test-wall-timeout"})};
CHECK(commandline.error == "--test-wall-timeout needs a number of seconds");
}
SUBCASE("the first error is the one told")
{
auto const commandline{parse({"--test", "--test-timeout", "x", "--test-wall-timeout", "y"})};
CHECK(commandline.error == "--test-timeout needs a number of seconds");
}
SUBCASE("values of other options aren't taken for options")
{
auto const commandline{parse({"-s", "--test", "-ini", "--test-timeout", "-v", "--test", "-seed", "--test"})};
auto const commandline{parse({"-s", "--test", "-ini", "--test-timeout", "-v", "--test-wall-timeout", "-seed", "--test"})};
CHECK_FALSE(commandline.enabled);
CHECK(commandline.error.empty());
}
@@ -117,6 +124,25 @@ TEST_CASE("test mode: the command line")
}
}
TEST_CASE("test mode: the real time limit")
{
SUBCASE("given, it is the limit, 0 turns it off")
{
CHECK(simulation::wall_clock_limit(120.0, 3600.0) == 120.0);
CHECK(simulation::wall_clock_limit(0.0, 3600.0) == 0.0);
}
SUBCASE("not given, it is the simulation time limit and time for the loading")
{
CHECK(simulation::wall_clock_limit(std::nullopt, 240.0) == 240.0 + simulation::wall_timeout_loading_allowance);
CHECK(simulation::wall_clock_limit(std::nullopt, 3600.0) == 3600.0 + simulation::wall_timeout_loading_allowance);
}
SUBCASE("no simulation time limit, no real time limit unless given")
{
CHECK(simulation::wall_clock_limit(std::nullopt, 0.0) == 0.0);
CHECK(simulation::wall_clock_limit(300.0, 0.0) == 300.0);
}
}
TEST_CASE("test mode: the end conditions")
{
simulation::test_limits limits;