Smart wait for msg to arrive in channel test (#6260)

This commit is contained in:
Max 2024-06-13 11:53:15 +01:00 коммит произвёл GitHub
Родитель 9a50e06fb7
Коммит 4154079ece
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -1550,13 +1550,40 @@ TEST_CASE_FIXTURE(IORingbuffersFixture, "Key rotation")
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
// Assume this sleep is long enough for channel threads to fully catch up
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Wait for channel threads to fully catch up.
constexpr int wait_finish_attempts = 100;
for (int attempt = 0; attempt < wait_finish_attempts; attempt++)
{
bool skip_waiting{false};
{
std::lock_guard<std::mutex> guard(sent_by_1.lock);
skip_waiting |= sent_by_1.to_send.empty();
}
{
std::lock_guard<std::mutex> guard(sent_by_2.lock);
skip_waiting |= sent_by_2.to_send.empty();
}
if (skip_waiting)
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
finished.store(true);
channels1.join();
channels2.join();
{
std::lock_guard<std::mutex> guard(sent_by_1.lock);
REQUIRE(sent_by_1.to_send.empty());
}
{
std::lock_guard<std::mutex> guard(sent_by_2.lock);
REQUIRE(sent_by_2.to_send.empty());
}
// Validate results
REQUIRE(received_by_1 == expected_received_by_1);
REQUIRE(received_by_2 == expected_received_by_2);