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

[backport foxy] More reliable topic remapping test (#456) #817

Merged
merged 1 commit into from
Jul 9, 2021
Merged
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
24 changes: 13 additions & 11 deletions rosbag2_transport/test/rosbag2_transport/test_play_topic_remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <utility>
#include <vector>


#include "rosbag2_test_common/subscription_manager.hpp"

#include "rosbag2_transport/rosbag2_transport.hpp"
Expand All @@ -32,14 +31,13 @@

#include "rosbag2_play_test_fixture.hpp"


TEST_F(RosBag2PlayTestFixture, recorded_message_is_played_on_remapped_topic) {
// test constants
const std::string original_topic = "/topic_before_remap";
const std::string remapped_topic = "/topic_after_remap";
const int32_t test_value = 42;
const int64_t timestamp_in_milliseconds = 700;
const size_t expected_number_of_messages = 1;
const int64_t dt_in_milliseconds = 100;
const size_t expected_number_of_outgoing_messages = 5;
play_options_.topic_remapping_options =
{"--ros-args", "--remap", "topic_before_remap:=topic_after_remap"};

Expand All @@ -50,26 +48,30 @@ TEST_F(RosBag2PlayTestFixture, recorded_message_is_played_on_remapped_topic) {
{original_topic, "test_msgs/BasicTypes", "", ""}
};

std::vector<std::shared_ptr<rosbag2_storage::SerializedBagMessage>> messages =
{serialize_test_message(original_topic, timestamp_in_milliseconds, primitive_message1), };

std::vector<std::shared_ptr<rosbag2_storage::SerializedBagMessage>> messages;
for (auto i = 1u; i <= expected_number_of_outgoing_messages; ++i) {
messages.push_back(
serialize_test_message(original_topic, dt_in_milliseconds * i, primitive_message1));
}
auto prepared_mock_reader = std::make_unique<MockSequentialReader>();
prepared_mock_reader->prepare(messages, topic_types);
reader_ = std::make_unique<rosbag2_cpp::Reader>(std::move(prepared_mock_reader));

sub_->add_subscription<test_msgs::msg::BasicTypes>(remapped_topic, expected_number_of_messages);
// We can't reliably test for an exact number of messages to arrive.
// Therefore, we test that at least one message is being received over the remapped topic.
sub_->add_subscription<test_msgs::msg::BasicTypes>(
remapped_topic, 1u);
auto await_received_messages = sub_->spin_subscriptions();

rosbag2_transport::Rosbag2Transport rosbag2_transport(reader_, writer_, info_);

rosbag2_transport.play(
storage_options_, play_options_);
rosbag2_transport.play(storage_options_, play_options_);

await_received_messages.get();

auto replayed_test_primitives = sub_->get_received_messages<test_msgs::msg::BasicTypes>(
remapped_topic);
EXPECT_THAT(replayed_test_primitives, SizeIs(Ge(expected_number_of_messages)));
EXPECT_FALSE(replayed_test_primitives.empty());
EXPECT_THAT(
replayed_test_primitives,
Each(Pointee(Field(&test_msgs::msg::BasicTypes::int32_value, test_value))));
Expand Down