Skip to content

Commit

Permalink
Modifies play_until_is_equal_to_the_total_duration
Browse files Browse the repository at this point in the history
The test body now evaluates a bag whose duration is exactly the same
as given timestamp in PlayOptions.

Signed-off-by: Agustin Alba Chicar <[email protected]>
  • Loading branch information
agalbachicar committed Jun 21, 2022
1 parent 9faf6a9 commit fa3654f
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions rosbag2_transport/test/rosbag2_transport/test_play_until.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,40 @@ TEST_F(RosBag2PlayUntilTestFixture, playback_duration_overrides_play_until)

TEST_F(RosBag2PlayUntilTestFixture, play_until_is_equal_to_the_total_duration)
{
InitPlayerWithPlaybackUntilAndPlay(
150 /* playback_until_timestamp_millis */, 1 /* num messages topic 1 */,
1 /* num messages topic 2 */, 150 /* playback_duration_millis */);
auto primitive_message1 = get_messages_basic_types()[0];
auto primitive_message2 = get_messages_basic_types()[0];
primitive_message1->int32_value = 1;
primitive_message2->int32_value = 2;

auto replayed_test_primitives = sub_->get_received_messages<test_msgs::msg::BasicTypes>(
kTopic1_);
EXPECT_THAT(replayed_test_primitives, SizeIs(Eq(1u)));
EVAL_REPLAYED_PRIMITIVES(replayed_test_primitives);
auto topic_types = std::vector<rosbag2_storage::TopicMetadata>{
{kTopic1Name_, "test_msgs/BasicTypes", "", ""}};

auto replayed_test_arrays = sub_->get_received_messages<test_msgs::msg::Arrays>(
kTopic2_);
EXPECT_THAT(replayed_test_arrays, SizeIs(Eq(1u)));
EVAL_REPLAYED_BOOL_ARRAY_PRIMITIVES(replayed_test_arrays);
EVAL_REPLAYED_FLOAT_ARRAY_PRIMITIVES(replayed_test_arrays);
std::vector<std::shared_ptr<rosbag2_storage::SerializedBagMessage>> messages =
{
serialize_test_message(kTopic1Name_, 10, primitive_message1),
serialize_test_message(kTopic1Name_, 50, primitive_message2),
};

auto prepared_mock_reader = std::make_unique<MockSequentialReader>();
prepared_mock_reader->prepare(messages, topic_types);
auto reader = std::make_unique<rosbag2_cpp::Reader>(std::move(prepared_mock_reader));

// Expect to receive 1 message from play() and 2 messages from play_next in second round
sub_->add_subscription<test_msgs::msg::BasicTypes>(kTopic1_, messages.size());
play_options_.playback_until_timestamp = RCL_MS_TO_NS(50);

std::shared_ptr<MockPlayer> player_ = std::make_shared<MockPlayer>(
std::move(reader), storage_options_, play_options_);

// Wait for discovery to match publishers with subscribers
ASSERT_TRUE(sub_->spin_and_wait_for_matched(player_->get_list_of_publishers(), 5s));

auto await_received_messages = sub_->spin_subscriptions();
ASSERT_TRUE(player_->play());

await_received_messages.get();
auto replayed_topic1 = sub_->get_received_messages<test_msgs::msg::BasicTypes>(kTopic1_);
EXPECT_THAT(replayed_topic1, SizeIs(messages.size()));
EXPECT_EQ(replayed_topic1[0]->int32_value, 1);
EXPECT_EQ(replayed_topic1[1]->int32_value, 2);
}

0 comments on commit fa3654f

Please sign in to comment.