Skip to content

Commit

Permalink
Fix flakiness in the TopicInfo test
Browse files Browse the repository at this point in the history
The flakiness appears to be a timing issue. The fix here involves running
the loop that waits for the input messages in a separate thread before
starting the publisher.

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Nov 4, 2024
1 parent b0328a1 commit 7bbcbeb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <filesystem>
#include <fstream>
#include <future>
#include <iostream>
#include <string>
#include <ignition/msgs.hh>
Expand Down Expand Up @@ -115,23 +116,29 @@ TEST(ignTest, TopicInfo)
IGN_TRANSPORT_TEST_DIR,
"INTEGRATION_twoProcsPublisher_aux");

testing::forkHandlerType pi = testing::forkAndRun(publisher_path.c_str(),
g_partition.c_str());

// Check the 'ign topic -i' command.
std::string ign = std::string(IGN_PATH);

unsigned int retries = 0u;
bool infoFound = false;
std::string output;

while (!infoFound && retries++ < 10u)
{
output = custom_exec_str(ign + " topic -t /foo -i " + g_ignVersion);
infoFound = output.size() > 50u;
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
auto testLoop = std::async(std::launch::async, [&]{
while (!infoFound && retries++ < 10u)
{
std::cout << "Waiting for topic ...\n";
output = custom_exec_str(ign + " topic -t /foo -i " + g_ignVersion);
infoFound = output.size() > 50u;
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
});

std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "Fork and run " << publisher_path << std::endl;
testing::forkHandlerType pi = testing::forkAndRun(publisher_path.c_str(),
g_partition.c_str());

testLoop.wait();
EXPECT_TRUE(infoFound) << "OUTPUT["
<< output << "] Size[" << output.size()
<< "]. Expected Size=50" << std::endl;
Expand Down

0 comments on commit 7bbcbeb

Please sign in to comment.