isapego commented on code in PR #1272:
URL: https://github.com/apache/ignite-3/pull/1272#discussion_r1010557039
##########
modules/platforms/cpp/tests/client-test/main.cpp:
##########
@@ -40,9 +73,17 @@ void before_all() {
}
int main(int argc, char **argv) {
+ ignite::IgniteRunner runner;
+
+ set_process_abort_handler([&](int signal) {
+ std::cout << "Caught signal " << signal << " during tests" <<
std::endl;
+
+ runner.stop();
+ });
Review Comment:
I believe, `before_all` should be called before this code. :)
##########
modules/platforms/cpp/tests/client-test/main.cpp:
##########
@@ -22,8 +22,41 @@
#include <gtest/gtest.h>
#include <chrono>
+#include <csignal>
#include <thread>
+namespace {
+/** Shutdown handler that cleans up resources. */
+std::function<void(int)> shutdown_handler;
+
+/**
+ * Receives OS signal and handles it.
+ *
+ * @param signum Signal value.
+ */
+void signal_handler(int signum) {
+ shutdown_handler(signum);
+
+ signal(signum, SIG_DFL);
+
+ raise(signum);
+}
+}
+
+/**
+ * Sets process abortion (SIGABRT, SIGINT, SIGSEGV signals) handler.
+ *
+ * @param handler Abortion handler.
+ */
+void set_process_abort_handler(std::function<void(int)> handler) {
+ // Install signal handlers to clean up resources on early exit.
+ signal(SIGABRT, signal_handler);
+ signal(SIGINT, signal_handler);
+ signal(SIGSEGV, signal_handler);
+
+ shutdown_handler = std::move(handler);
Review Comment:
Handler should be set prior to signal interceptors or we are going to get
signal while handling signal in some cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]