Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20655] Fix flakey Log tests #4582

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions test/unittest/logging/LogTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,12 @@ TEST_F(LogTests, stdouterr_consumer_stream)
std::vector<Log::Entry> LogTests::HELPER_WaitForEntries(
uint32_t amount)
{
size_t entries = 0;
for (uint32_t i = 0; i != AsyncTries; i++)
{
entries = mockConsumer->ConsumedEntries().size();
if (entries == amount)
auto entries = mockConsumer->ConsumedEntries();
if (entries.size() == amount)
{
break;
return entries;
}
this_thread::sleep_for(chrono::milliseconds(AsyncWaitMs));
}
Expand Down
7 changes: 3 additions & 4 deletions test/unittest/logging/log_macros/LogMacros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ class LogMacrosTests : public ::testing::Test
std::vector<Log::Entry> HELPER_WaitForEntries(
uint32_t amount)
{
size_t entries = 0;
for (uint32_t i = 0; i != AsyncTries; i++)
{
entries = mockConsumer->ConsumedEntries().size();
if (entries == amount)
auto entries = mockConsumer->ConsumedEntries();
if (entries.size() == amount)
{
break;
return entries;
}
this_thread::sleep_for(chrono::milliseconds(AsyncWaitMs));
}
Expand Down
15 changes: 10 additions & 5 deletions test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ TEST_F(LogMacrosTests, default_macros_test)
# endif // Visual Studio specific behavior
#endif // Check default macro values

#if !HAVE_LOG_NO_INFO && \
// Result depends on the log configuration
#if !HAVE_LOG_NO_INFO && \
(defined(FASTDDS_ENFORCE_LOG_INFO) || \
((defined(__INTERNALDEBUG) || defined(_INTERNALDEBUG)) && (defined(_DEBUG) || defined(__DEBUG) || \
!defined(NDEBUG)))
static constexpr unsigned int expected_result = 3;
!defined(NDEBUG))))
constexpr unsigned int expected_result = 3;
#else
static constexpr unsigned int expected_result = 2;
constexpr unsigned int expected_result = 2;
#endif // debug macros check

auto consumedEntries = HELPER_WaitForEntries(expected_result);
// Warning and error should always be logged.
// Info might be logged depending on the log configuration.
// We always wait for 3 entries, though not all of them might be present.
auto consumedEntries = HELPER_WaitForEntries(3u);
Mario-DL marked this conversation as resolved.
Show resolved Hide resolved
ASSERT_EQ(expected_result, consumedEntries.size());
}

Expand Down
Loading