fix: Improve Repeat implementation (#1775)

This commit is contained in:
Sergey Kuznetsov
2024-12-11 15:07:48 +00:00
committed by GitHub
parent c41399ef8e
commit b53cfd0ec1
3 changed files with 41 additions and 14 deletions

View File

@@ -34,7 +34,7 @@
using namespace util;
using testing::AtLeast;
struct RepeatTests : SyncAsioContextTest {
struct RepeatTest : SyncAsioContextTest {
Repeat repeat{ctx};
testing::StrictMock<testing::MockFunction<void()>> handlerMock;
@@ -51,14 +51,14 @@ struct RepeatTests : SyncAsioContextTest {
}
};
TEST_F(RepeatTests, CallsHandler)
TEST_F(RepeatTest, CallsHandler)
{
repeat.start(std::chrono::milliseconds{1}, handlerMock.AsStdFunction());
EXPECT_CALL(handlerMock, Call).Times(AtLeast(10));
runContextFor(std::chrono::milliseconds{20});
}
TEST_F(RepeatTests, StopsOnStop)
TEST_F(RepeatTest, StopsOnStop)
{
withRunningContext([this]() {
repeat.start(std::chrono::milliseconds{1}, handlerMock.AsStdFunction());
@@ -68,10 +68,10 @@ TEST_F(RepeatTests, StopsOnStop)
});
}
TEST_F(RepeatTests, RunsAfterStop)
TEST_F(RepeatTest, RunsAfterStop)
{
withRunningContext([this]() {
for ([[maybe_unused]] auto _ : std::ranges::iota_view(0, 2)) {
for ([[maybe_unused]] auto i : std::ranges::iota_view(0, 2)) {
repeat.start(std::chrono::milliseconds{1}, handlerMock.AsStdFunction());
EXPECT_CALL(handlerMock, Call).Times(AtLeast(1));
std::this_thread::sleep_for(std::chrono::milliseconds{10});
@@ -79,3 +79,16 @@ TEST_F(RepeatTests, RunsAfterStop)
}
});
}
struct RepeatDeathTest : RepeatTest {};
TEST_F(RepeatDeathTest, DiesWhenStartCalledTwice)
{
EXPECT_DEATH(
{
repeat.start(std::chrono::seconds{1}, []() {});
repeat.start(std::chrono::seconds{1}, []() {});
},
"Assertion .* failed.*"
);
}