Skip to content

Commit

Permalink
relax msg count check in RF comms integration test (#1920)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Mar 8, 2023
1 parent d1f9622 commit f8f6eee
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/integration/rf_comms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ TEST_F(RFCommsTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(RFComms))
{
// Verify msg content
std::lock_guard<std::mutex> lock(mutex);
std::string expected = "hello world " + std::to_string(msgCounter);

ignition::msgs::StringMsg receivedMsg;
receivedMsg.ParseFromString(_msg.data());

EXPECT_EQ(expected, receivedMsg.data());
EXPECT_NE(std::string::npos, receivedMsg.data().find("hello world"));
ASSERT_GT(_msg.header().data_size(), 0);
EXPECT_EQ("rssi", _msg.header().data(0).key());
msgCounter++;
Expand Down Expand Up @@ -106,14 +105,16 @@ TEST_F(RFCommsTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(RFComms))
server.Run(true, 100, false);
}

// Verify subscriber received all msgs.
// there is a non-zero probability that the packet may be lost
// Verify subscriber received most of the msgs.
unsigned int expectedMsgCount = static_cast<unsigned int>(pubCount * 0.5);
int sleep = 0;
bool done = false;
while (!done && sleep++ < 10)
{
std::lock_guard<std::mutex> lock(mutex);
done = msgCounter == pubCount;
done = msgCounter > expectedMsgCount;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
EXPECT_EQ(pubCount, msgCounter);
EXPECT_LT(expectedMsgCount, msgCounter);
}

0 comments on commit f8f6eee

Please sign in to comment.