Skip to content

Commit

Permalink
ign_TEST: improve reliability of TopicPublish test
Browse files Browse the repository at this point in the history
Keep calling `ign topic --pub` if messages aren't received.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed May 11, 2021
1 parent 9584a1e commit f39b7d7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/cmd/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,20 @@ TEST(ignTest, TopicPublish)

// Check the 'ign topic -p' command.
std::string ign = std::string(IGN_PATH) + "/ign";
std::string output = custom_exec_str(ign +
" topic -t /bar -m ign_msgs.StringMsg -p 'data:\"good_value\"' " +
g_ignVersion);
std::string output;

ASSERT_TRUE(output.empty()) << output;
unsigned int retries = 0;
while (g_topicCBStr != "good_value" && retries++ < 20u)
while (g_topicCBStr != "good_value" && retries++ < 200u)
{
std::this_thread::sleep_for(std::chrono::milliseconds(300));
// Send on alternating retries
if (retries % 2)
{
output = custom_exec_str(ign +
" topic -t /bar -m ign_msgs.StringMsg -p 'data:\"good_value\"' " +
g_ignVersion);
EXPECT_TRUE(output.empty()) << output;
}
std::this_thread::sleep_for(std::chrono::milliseconds(30));
}
EXPECT_EQ(g_topicCBStr, "good_value");

Expand All @@ -351,14 +356,14 @@ TEST(ignTest, TopicPublish)
output = custom_exec_str(ign +
" topic -t / -m ign_msgs.StringMsg -p 'data:\"good_value\"' "+
g_ignVersion);
EXPECT_EQ(output.compare(0, error.size(), error), 0);
EXPECT_EQ(output.compare(0, error.size(), error), 0) << output;

// Try to publish using an incorrect number of arguments.
error = "The following argument was not expected: wrong_topic";
output = custom_exec_str(ign +
" topic -t / wrong_topic -m ign_msgs.StringMsg -p 'data:\"good_value\"' "+
g_ignVersion);
EXPECT_EQ(output.compare(0, error.size(), error), 0);
EXPECT_EQ(output.compare(0, error.size(), error), 0) << output;
}

//////////////////////////////////////////////////
Expand Down

0 comments on commit f39b7d7

Please sign in to comment.