diff --git a/test/test.cpp b/test/test.cpp index 665a161..d04c48e 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -162,3 +163,30 @@ TEST_CASE("exit-condition-looping") } } +TEST_CASE("signal-handler-reuse") +{ + std::map signal_map({{SIGINT, 1 << 0}, + {SIGTERM, 1 << 1}, + {SIGUSR1, 1 << 2}, + {SIGUSR2, 1 << 3}}); + + sgnl::AtomicCondition condition(0); + sgnl::SignalHandler signal_handler(signal_map, condition); + + for( auto p : signal_map ) + { + std::promise signal_handler_thread_id; + std::future ft_sig_handler = + std::async(std::launch::async, [&]() { + signal_handler_thread_id.set_value(pthread_self()); + return signal_handler(); + }); + REQUIRE( + pthread_kill( + signal_handler_thread_id.get_future().get(), + p.first) == 0 ); + REQUIRE( ft_sig_handler.get() == p.first ); + REQUIRE( condition.get() == p.second ); + } +} +