mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 06:26:01 +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:
@@ -11,7 +11,10 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "simulation/simulationtestrules.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
|
||||
// integration test mode (eu07 --test -s <scenery>, eu07/maszyna#541): the scenery runs unattended in a tight
|
||||
// fixed-step loop and the simulator quits with an exit code saying how the test went
|
||||
@@ -38,16 +41,26 @@ public:
|
||||
// ends the test with given result, without closing the application: for the ways out that close it anyway
|
||||
// (a bad command line, a failed start, an exception). returns false if the test had already ended
|
||||
bool conclude(test_result Result, std::string_view Reason);
|
||||
// (re)sets the real time limit of the run [s] since the start of the simulator, 0 = none. the first limit
|
||||
// starts the watchdog, which ends a run still going at the limit with the timeout code, whatever it's doing
|
||||
void watch_wall_clock(double Limit);
|
||||
|
||||
bool finished() const { return m_finished; }
|
||||
// exit code of the process: the result, or error while the test hasn't finished
|
||||
int exit_code() const { return static_cast<int>(m_finished ? m_result : test_result::error); }
|
||||
int exit_code() const;
|
||||
|
||||
private:
|
||||
// the watchdog's check, at Elapsed seconds of real time since the start of the simulator
|
||||
void check_wall_clock(double Elapsed);
|
||||
|
||||
// the watchdog may end the test from its own thread
|
||||
mutable std::mutex m_lock;
|
||||
bool m_started { false };
|
||||
bool m_finished { false };
|
||||
std::atomic<bool> m_finished { false };
|
||||
test_result m_result { test_result::error };
|
||||
test_progress m_progress;
|
||||
std::atomic<double> m_walllimit { 0.0 }; // [s] since the start of the simulator, 0 = none
|
||||
std::jthread m_watchdog;
|
||||
};
|
||||
|
||||
// the test of the run
|
||||
|
||||
Reference in New Issue
Block a user