Skip to content

Commit

Permalink
Add rapid fire test
Browse files Browse the repository at this point in the history
Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Aug 21, 2024
1 parent 7945e18 commit 3611f53
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/SignalHandler_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,39 @@ TEST(SignalHandler, MultipleThreads)
for (int i = 0; i < threadCount; ++i)
EXPECT_EQ(SIGINT, results[i]);
}

/////////////////////////////////////////////////
TEST(SignalHandler, RapidFire)
{
resetSignals();
std::condition_variable cv;
std::mutex countMutex;
int countHandlerCalls = 0;
constexpr int kNumSignals = 100;
auto cb = [&](int _sig)
{
if (_sig == SIGTERM)
{
std::lock_guard<std::mutex> lk(countMutex);
++countHandlerCalls;
if (countHandlerCalls >= kNumSignals)
{
cv.notify_one();
}
}
};
common::SignalHandler handler1;
EXPECT_TRUE(handler1.AddCallback(cb));

for (int i=0; i < kNumSignals; ++i)
{
std::raise(SIGTERM);
std::this_thread::sleep_for(std::chrono::microseconds(100));
}

// wait for callback to be called kNumSignal times with a timeout
std::unique_lock<std::mutex> lk(countMutex);
cv.wait_for(lk, std::chrono::seconds(5),
[&] { return countHandlerCalls >= kNumSignals; });
EXPECT_GE(countHandlerCalls, kNumSignals);
}

0 comments on commit 3611f53

Please sign in to comment.