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

Add unit tests to cover message's send and received timestamps during recording #1641

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
25 changes: 24 additions & 1 deletion rosbag2_transport/test/rosbag2_transport/test_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ TEST_F(RecordIntegrationTestFixture, published_messages_from_multiple_topics_are
return mock_writer.get_messages().size() >= expected_messages;
});
auto recorded_messages = mock_writer.get_messages();
EXPECT_TRUE(ret) << "failed to capture expected messages in time";
EXPECT_TRUE(ret) << "failed to capture expected messages in time" <<
"recorded messages = " << recorded_messages.size();
EXPECT_THAT(recorded_messages, SizeIs(expected_messages));
stop_spinning();

auto recorded_topics = mock_writer.get_topics();
ASSERT_THAT(recorded_topics, SizeIs(2));
Expand All @@ -87,6 +89,27 @@ TEST_F(RecordIntegrationTestFixture, published_messages_from_multiple_topics_are
EXPECT_THAT(string_messages[0]->string_value, Eq(string_message->string_value));
EXPECT_THAT(array_messages[0]->bool_values, Eq(array_message->bool_values));
EXPECT_THAT(array_messages[0]->float32_values, Eq(array_message->float32_values));

// Check for send and received timestamps
bool rmw_has_send_timestamp_support = true;
#ifdef _WIN32
if (std::string(rmw_get_implementation_identifier()).find("rmw_connextdds") !=
std::string::npos)
{
rmw_has_send_timestamp_support = false;
}
#endif
for (const auto & message : recorded_messages) {
EXPECT_NE(message->recv_timestamp, 0) << "topic : " << message->topic_name;
if (rmw_has_send_timestamp_support) {
// Check that the send_timestamp is not the same as the clock message
EXPECT_NE(message->send_timestamp, 0);
EXPECT_THAT(message->recv_timestamp, Ge(message->send_timestamp));
} else {
// if rwm has not sent timestamp support, send_timestamp must be zero
EXPECT_EQ(message->send_timestamp, 0);
}
}
}

TEST_F(RecordIntegrationTestFixture, can_record_again_after_stop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ TEST_F(RecordIntegrationTestFixture, record_all_with_sim_time)
// check that the timestamp is same as the clock message
EXPECT_THAT(string_messages[0]->recv_timestamp, time_value);

bool rwm_has_timestamp_support = true;
bool rmw_has_timestamp_support = true;

#ifdef _WIN32
if (std::string(rmw_get_implementation_identifier()).find("rmw_connextdds") !=
std::string::npos)
{
rwm_has_timestamp_support = false;
rmw_has_timestamp_support = false;
}
#endif

if (rwm_has_timestamp_support) {
if (rmw_has_timestamp_support) {
// Check that the send_timestamp is not the same as the clock message
EXPECT_NE(string_messages[0]->send_timestamp, time_value);
EXPECT_NE(string_messages[0]->send_timestamp, 0);
Expand Down
Loading