From d1b85beef4691db13f25d8d869fb6b0a48715581 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Mon, 4 Nov 2024 17:39:28 -0600 Subject: [PATCH] Fix flakiness in the TopicInfo test 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 --- src/cmd/gz_TEST.cc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cmd/gz_TEST.cc b/src/cmd/gz_TEST.cc index f50a235e2..909fa0a23 100644 --- a/src/cmd/gz_TEST.cc +++ b/src/cmd/gz_TEST.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -115,9 +116,6 @@ 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); @@ -125,13 +123,22 @@ TEST(ignTest, TopicInfo) 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;