From 1f533cd56e70c5a41c69310b27ddadeba15213b3 Mon Sep 17 00:00:00 2001 From: Michael Orlov Date: Tue, 21 May 2024 13:23:31 -0700 Subject: [PATCH] Fix for regression in `open_succeeds_twice` and `minimal_writer_example` tests (#1667) * Use test-specific temp subfolder to avoid leftovers from previous run Signed-off-by: Michael Orlov * Address flakiness in TestRosbag2CPPAPI::minimal_writer_example - The `serialized_msg2` is not owning the serialized data after the first call writer.write(serialized_msg2,..). i.e. need to use another message or another API in test for second call to writer.write(msg). Signed-off-by: Michael Orlov --------- Signed-off-by: Michael Orlov (cherry picked from commit 8523995bee50be2128df862512b44df7531e8456) # Conflicts: # rosbag2_compression/test/rosbag2_compression/test_sequential_compression_writer.cpp --- .../test_sequential_compression_writer.cpp | 9 +++++++++ .../test/rosbag2_tests/test_rosbag2_cpp_api.cpp | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/rosbag2_compression/test/rosbag2_compression/test_sequential_compression_writer.cpp b/rosbag2_compression/test/rosbag2_compression/test_sequential_compression_writer.cpp index 4b5c3589b..473b09c5f 100644 --- a/rosbag2_compression/test/rosbag2_compression/test_sequential_compression_writer.cpp +++ b/rosbag2_compression/test/rosbag2_compression/test_sequential_compression_writer.cpp @@ -199,7 +199,11 @@ TEST_F(SequentialCompressionWriterTest, open_succeeds_on_supported_compression_f kDefaultCompressionQueueSize, kDefaultCompressionQueueThreads}; initializeWriter(compression_options); +<<<<<<< HEAD auto tmp_dir = rcpputils::fs::temp_directory_path() / "path_not_empty"; +======= + auto tmp_dir = tmp_dir_ / "path_not_empty"; +>>>>>>> 8523995b (Fix for regression in `open_succeeds_twice` and `minimal_writer_example` tests (#1667)) auto storage_options = rosbag2_storage::StorageOptions(); storage_options.uri = tmp_dir.string(); @@ -214,8 +218,13 @@ TEST_F(SequentialCompressionWriterTest, open_succeeds_twice) kDefaultCompressionQueueSize, kDefaultCompressionQueueThreads}; initializeWriter(compression_options); +<<<<<<< HEAD auto tmp_dir = rcpputils::fs::temp_directory_path() / "path_not_empty"; auto tmp_dir_next = rcpputils::fs::temp_directory_path() / "path_not_empty_next"; +======= + auto tmp_dir = tmp_dir_ / "path_not_empty"; + auto tmp_dir_next = tmp_dir_ / "path_not_empty_next"; +>>>>>>> 8523995b (Fix for regression in `open_succeeds_twice` and `minimal_writer_example` tests (#1667)) auto storage_options = rosbag2_storage::StorageOptions(); auto storage_options_next = rosbag2_storage::StorageOptions(); diff --git a/rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_api.cpp b/rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_api.cpp index 982d46093..04b356215 100644 --- a/rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_api.cpp +++ b/rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_api.cpp @@ -106,9 +106,7 @@ TEST_P(TestRosbag2CPPAPI, minimal_writer_example) writer.open(rosbag_directory_next.string()); // write same topic to different bag - writer.write( - serialized_msg2, "/yet/another/topic", "test_msgs/msg/BasicTypes", - rclcpp::Clock().now()); + writer.write(bag_message, "/my/other/topic", "test_msgs/msg/BasicTypes"); // close by scope } @@ -152,7 +150,7 @@ TEST_P(TestRosbag2CPPAPI, minimal_writer_example) &extracted_serialized_msg, &extracted_test_msg); EXPECT_EQ(test_msg, extracted_test_msg); - EXPECT_EQ("/yet/another/topic", topic); + EXPECT_EQ("/my/other/topic", topic); } // alternative reader