Commit e3c1467a authored by Dominik Charousset's avatar Dominik Charousset

Pass along max runtime setting in unit tests

parent 34e75dd0
...@@ -76,8 +76,10 @@ using pong_atom = atom_constant<atom("pong")>; ...@@ -76,8 +76,10 @@ using pong_atom = atom_constant<atom("pong")>;
*/ */
std::thread run_prog(const char* arg, uint16_t port, bool use_asio) { std::thread run_prog(const char* arg, uint16_t port, bool use_asio) {
return detail::run_program(invalid_actor, caf::test::engine::path(), "-n", return detail::run_program(invalid_actor, test::engine::path(), "-n",
"-s", CAF_XSTR(CAF_SUITE), "--", arg, "-p", port, "-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(), "--",
arg, "-p", port,
(use_asio ? "--use-asio" : "")); (use_asio ? "--use-asio" : ""));
} }
......
...@@ -186,8 +186,10 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) { ...@@ -186,8 +186,10 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
[&](uint16_t port) { [&](uint16_t port) {
CAF_MESSAGE("server is running on port " << port); CAF_MESSAGE("server is running on port " << port);
if (spawn_client) { if (spawn_client) {
auto child = detail::run_program(self, bin_path, "-n", "-s", auto child = detail::run_program(self, bin_path, "-n",
CAF_XSTR(CAF_SUITE), "--", "-c", port, "-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(),
"--", "-c", port,
(use_asio ? "--use-asio" : "")); (use_asio ? "--use-asio" : ""));
CAF_MESSAGE("block till child process has finished"); CAF_MESSAGE("block till child process has finished");
child.join(); child.join();
......
...@@ -481,7 +481,8 @@ void test_remote_actor(const char* path, bool run_remote, bool use_asio) { ...@@ -481,7 +481,8 @@ void test_remote_actor(const char* path, bool run_remote, bool use_asio) {
thread child; thread child;
if (run_remote) { if (run_remote) {
child = detail::run_program(self, path, "-n", "-s", CAF_XSTR(CAF_SUITE), child = detail::run_program(self, path, "-n", "-s", CAF_XSTR(CAF_SUITE),
"--", "-c", port2, "-c", port1, "-g", gport, "-r", test::engine::max_runtime(), "--",
"-c", port2, "-c", port1, "-g", gport,
(use_asio ? "--use-asio" : "")); (use_asio ? "--use-asio" : ""));
} else { } else {
CAF_MESSAGE("please run client with: " CAF_MESSAGE("please run client with: "
......
...@@ -141,7 +141,8 @@ CAF_TEST(remote_spawn) { ...@@ -141,7 +141,8 @@ CAF_TEST(remote_spawn) {
if (r.opts.count("server") == 0) { if (r.opts.count("server") == 0) {
CAF_TEST_VERBOSE("run client program"); CAF_TEST_VERBOSE("run client program");
auto child = detail::run_program(invalid_actor, caf::test::engine::path(), auto child = detail::run_program(invalid_actor, caf::test::engine::path(),
"-n", "-s", CAF_XSTR(CAF_SUITE), "--", "-n", "-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(), "--",
"-c", port, "-c", port,
(use_asio ? "--use-asio" : "")); (use_asio ? "--use-asio" : ""));
child.join(); child.join();
......
...@@ -191,8 +191,10 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) { ...@@ -191,8 +191,10 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
[&](uint16_t port) { [&](uint16_t port) {
CAF_MESSAGE("server is running on port " << port); CAF_MESSAGE("server is running on port " << port);
if (spawn_client) { if (spawn_client) {
auto child = detail::run_program(self, bin_path, "-n", "-s", auto child = detail::run_program(self, bin_path, "-n",
CAF_XSTR(CAF_SUITE), "--", "-c", port, "-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(),
"--", "-c", port,
(use_asio ? "--use-asio" : "")); (use_asio ? "--use-asio" : ""));
CAF_MESSAGE("block till child process has finished"); CAF_MESSAGE("block till child process has finished");
child.join(); child.join();
......
...@@ -133,9 +133,10 @@ CAF_TEST(test_typed_remote_actor) { ...@@ -133,9 +133,10 @@ CAF_TEST(test_typed_remote_actor) {
// execute client_part() in a separate process, // execute client_part() in a separate process,
// connected via localhost socket // connected via localhost socket
scoped_actor self; scoped_actor self;
auto child = detail::run_program(self, caf::test::engine::path(), "-n", auto child = detail::run_program(self, test::engine::path(), "-n",
"-s", CAF_XSTR(CAF_SUITE), "-s", CAF_XSTR(CAF_SUITE),
"--", "-c", port, "-r", test::engine::max_runtime(), "--",
"-c", port,
(use_asio ? "--use-asio" : "")); (use_asio ? "--use-asio" : ""));
CAF_MESSAGE("block till child process has finished"); CAF_MESSAGE("block till child process has finished");
child.join(); child.join();
......
...@@ -220,6 +220,13 @@ public: ...@@ -220,6 +220,13 @@ public:
/// @returns The path to executable set via ::path(char*) or `nullptr`. /// @returns The path to executable set via ::path(char*) or `nullptr`.
static char* path(); static char* path();
/// Returns the maximum number of seconds a test case is allowed to run.
static int max_runtime();
/// Sets the maximum number of seconds a test case is
/// allowed to run to `value`.
static void max_runtime(int value);
/// Adds a test to the engine. /// Adds a test to the engine.
/// @param name The name of the suite. /// @param name The name of the suite.
/// @param ptr The test to register. /// @param ptr The test to register.
...@@ -231,7 +238,6 @@ public: ...@@ -231,7 +238,6 @@ public:
/// that no log file will be written. /// that no log file will be written.
/// @param verbosity_console The log verbosity on the console. /// @param verbosity_console The log verbosity on the console.
/// @param verbosity_file The log verbosity in the log file. /// @param verbosity_file The log verbosity in the log file.
/// @param max_runtime The maximum number of seconds a test shall run.
/// @param suites The regular expression of the tests to run. /// @param suites The regular expression of the tests to run.
/// @param not_suites Whether to colorize the output. /// @param not_suites Whether to colorize the output.
/// @returns `true` iff all tests succeeded. /// @returns `true` iff all tests succeeded.
...@@ -239,7 +245,6 @@ public: ...@@ -239,7 +245,6 @@ public:
const std::string& log_file, const std::string& log_file,
int verbosity_console, int verbosity_console,
int verbosity_file, int verbosity_file,
int max_runtime,
const std::string& suites, const std::string& suites,
const std::string& not_suites, const std::string& not_suites,
const std::string& tests, const std::string& tests,
...@@ -284,6 +289,7 @@ private: ...@@ -284,6 +289,7 @@ private:
size_t check_line_ = 0; size_t check_line_ = 0;
test* current_test_ = nullptr; test* current_test_ = nullptr;
std::map<std::string, std::vector<std::unique_ptr<test>>> suites_; std::map<std::string, std::vector<std::unique_ptr<test>>> suites_;
int max_runtime_ = 30; // 30s per default
}; };
namespace detail { namespace detail {
......
...@@ -248,6 +248,14 @@ char* engine::path() { ...@@ -248,6 +248,14 @@ char* engine::path() {
return instance().path_; return instance().path_;
} }
int engine::max_runtime() {
return instance().max_runtime_;
}
void engine::max_runtime(int value) {
instance().max_runtime_ = value;
}
void engine::add(const char* cstr_name, std::unique_ptr<test> ptr) { void engine::add(const char* cstr_name, std::unique_ptr<test> ptr) {
std::string name = cstr_name ? cstr_name : ""; std::string name = cstr_name ? cstr_name : "";
auto& suite = instance().suites_[name]; auto& suite = instance().suites_[name];
...@@ -264,7 +272,6 @@ bool engine::run(bool colorize, ...@@ -264,7 +272,6 @@ bool engine::run(bool colorize,
const std::string& log_file, const std::string& log_file,
int verbosity_console, int verbosity_console,
int verbosity_file, int verbosity_file,
int max_runtime,
const std::string& suites_str, const std::string& suites_str,
const std::string& not_suites_str, const std::string& not_suites_str,
const std::string& tests_str, const std::string& tests_str,
...@@ -360,7 +367,7 @@ bool engine::run(bool colorize, ...@@ -360,7 +367,7 @@ bool engine::run(bool colorize,
log.verbose() << color(yellow) << "- " << color(reset) << t->name() log.verbose() << color(yellow) << "- " << color(reset) << t->name()
<< '\n'; << '\n';
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
watchdog::start(max_runtime); watchdog::start(max_runtime());
try { try {
t->run(); t->run();
} catch (const detail::require_error&) { } catch (const detail::require_error&) {
...@@ -493,7 +500,7 @@ int main(int argc, char** argv) { ...@@ -493,7 +500,7 @@ int main(int argc, char** argv) {
// default values. // default values.
int verbosity_console = 3; int verbosity_console = 3;
int verbosity_file = 3; int verbosity_file = 3;
int max_runtime = 10; int max_runtime = 0;
std::string log_file; std::string log_file;
std::string suites = ".*"; std::string suites = ".*";
std::string not_suites; std::string not_suites;
...@@ -542,14 +549,15 @@ int main(int argc, char** argv) { ...@@ -542,14 +549,15 @@ int main(int argc, char** argv) {
return 1; return 1;
} }
auto colorize = res.opts.count("no-colors") == 0; auto colorize = res.opts.count("no-colors") == 0;
if (divider < argc) { if (divider < argc)
engine::args(argc - divider - 1, argv + divider + 1); engine::args(argc - divider - 1, argv + divider + 1);
} else { else
engine::args(0, argv); engine::args(0, argv);
} if (res.opts.count("max-runtime") > 0)
engine::max_runtime(max_runtime);
auto result = engine::run(colorize, log_file, verbosity_console, auto result = engine::run(colorize, log_file, verbosity_console,
verbosity_file, max_runtime, suites, verbosity_file, suites,
not_suites, tests, not_tests); not_suites, tests, not_tests);
return result ? 0 : 1; return result ? 0 : 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment