Skip to content
Open
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
2 changes: 1 addition & 1 deletion rosbag2_py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ if(BUILD_TESTING)
APPEND_ENV "${append_env_vars}"
ENV "${set_env_vars}"
)
ament_add_pytest_test(test_transport_py
ament_add_ros_isolated_pytest_test(test_transport_py
"test/test_transport.py"
APPEND_ENV "${append_env_vars}"
ENV "${set_env_vars}"
Expand Down
53 changes: 36 additions & 17 deletions rosbag2_py/src/rosbag2_py/_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,19 @@ class Player
// Don't install signal handlers to keep signal handling simple in the Python layer
rclcpp::init(arguments.argc(), arguments.argv(),
rclcpp::InitOptions(), rclcpp::SignalHandlerOptions::None);
player_ = std::make_shared<rosbag2_transport::Player>(storage_options, play_options, node_name);
// If constructing the Player fails (e.g. the bag needs a converter plugin
// that is not installed), the destructor never runs, so rclcpp::shutdown()
// would otherwise only be called when the global Context is destroyed at
// process exit.
// Ensure the Context is shut down on the failure path so the program can exit
// cleanly with the expected error code.
try {
player_ =
std::make_shared<rosbag2_transport::Player>(storage_options, play_options, node_name);
} catch (...) {
rclcpp::shutdown();
throw;
}
}

virtual ~Player()
Expand Down Expand Up @@ -580,23 +592,30 @@ class Recorder
rclcpp::init(arguments.argc(), arguments.argv(),
rclcpp::InitOptions(), rclcpp::SignalHandlerOptions::None);

if (!record_options.rmw_serialization_format.empty() &&
record_options.output_serialization_format.empty())
{
record_options.output_serialization_format = record_options.rmw_serialization_format;
PyErr_WarnEx(PyExc_DeprecationWarning,
"The rmw_serialization_format option is deprecated and will be removed in a "
"future release.\nPlease use output_serialization_format instead.",
1
);
}
if (record_options.output_serialization_format.empty()) {
record_options.output_serialization_format = std::string(rmw_get_serialization_format());
}
auto writer = rosbag2_transport::ReaderWriterFactory::make_writer(record_options);
// See the Player constructor: if constructing the Recorder throws, shut the
// Context down here so it is not left to be destroyed at process exit.
try {
if (!record_options.rmw_serialization_format.empty() &&
record_options.output_serialization_format.empty())
{
record_options.output_serialization_format = record_options.rmw_serialization_format;
PyErr_WarnEx(PyExc_DeprecationWarning,
"The rmw_serialization_format option is deprecated and will be removed in a "
"future release.\nPlease use output_serialization_format instead.",
1
);
}
if (record_options.output_serialization_format.empty()) {
record_options.output_serialization_format = std::string(rmw_get_serialization_format());
}
auto writer = rosbag2_transport::ReaderWriterFactory::make_writer(record_options);

recorder_ = std::make_shared<rosbag2_transport::Recorder>(
std::move(writer), storage_options, record_options, node_name);
recorder_ = std::make_shared<rosbag2_transport::Recorder>(
std::move(writer), storage_options, record_options, node_name);
} catch (...) {
rclcpp::shutdown();
throw;
}
}

virtual ~Recorder()
Expand Down
7 changes: 4 additions & 3 deletions rosbag2_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ find_package(ament_index_cpp REQUIRED)

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
find_package(ament_cmake_ros REQUIRED)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

Expand All @@ -42,7 +43,7 @@ if(BUILD_TESTING)
find_package(std_msgs REQUIRED)
find_package(test_msgs REQUIRED)

ament_add_gmock(test_rosbag2_record_end_to_end
ament_add_ros_isolated_gmock(test_rosbag2_record_end_to_end
test/rosbag2_tests/test_rosbag2_record_end_to_end.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 180)
Expand All @@ -58,7 +59,7 @@ if(BUILD_TESTING)
ament_add_test_label(test_rosbag2_record_end_to_end xfail)
endif()

ament_add_gmock(test_rosbag2_play_end_to_end
ament_add_ros_isolated_gmock(test_rosbag2_play_end_to_end
test/rosbag2_tests/test_rosbag2_play_end_to_end.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET test_rosbag2_play_end_to_end)
Expand Down Expand Up @@ -120,7 +121,7 @@ if(BUILD_TESTING)
)
endif()

ament_add_gmock(test_rosbag2_cpp_get_service_info
ament_add_ros_isolated_gmock(test_rosbag2_cpp_get_service_info
test/rosbag2_tests/test_rosbag2_cpp_get_service_info.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET test_rosbag2_cpp_get_service_info)
Expand Down
1 change: 1 addition & 0 deletions rosbag2_tests/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<depend>ament_index_cpp</depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>rclcpp</test_depend>
Expand Down
Loading