From ec88f139217d4d3182d41af7525bdcc7088716ec Mon Sep 17 00:00:00 2001 From: Michael Orlov Date: Wed, 20 Mar 2024 17:00:22 -0700 Subject: [PATCH] Fix for false negative tests in rosbag2_py (#1592) * Fix for false negative tests in rosbag2_py - wait_for(condition: Callable, timout) was incorrectly returning True after the first iteration even if condition was false. Signed-off-by: Michael Orlov * Address review comments in regards bag_path optimization Signed-off-by: Michael Orlov --------- Signed-off-by: Michael Orlov (cherry picked from commit 66af3999f145a8910b567a6ab48993c83410754e) # Conflicts: # rosbag2_py/test/test_transport.py --- rosbag2_py/test/common.py | 2 +- rosbag2_py/test/test_transport.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rosbag2_py/test/common.py b/rosbag2_py/test/common.py index 70c0b8368a..8557da5afa 100644 --- a/rosbag2_py/test/common.py +++ b/rosbag2_py/test/common.py @@ -41,4 +41,4 @@ def wait_for( if clock.now() - start > timeout: return False time.sleep(sleep_time) - return True + return True diff --git a/rosbag2_py/test/test_transport.py b/rosbag2_py/test/test_transport.py index 2006ff44d5..13a8b42d13 100644 --- a/rosbag2_py/test/test_transport.py +++ b/rosbag2_py/test/test_transport.py @@ -13,9 +13,12 @@ # limitations under the License. import datetime +<<<<<<< HEAD import os from pathlib import Path import sys +======= +>>>>>>> 66af3999 (Fix for false negative tests in rosbag2_py (#1592)) import threading @@ -49,6 +52,7 @@ def test_options_qos_conversion(): assert record_options.topic_qos_profile_overrides == simple_overrides +<<<<<<< HEAD def test_player_log_level(): rosbag2_py.Player() # Test for default constructor valid_log_level = 'debug' @@ -72,6 +76,12 @@ def test_recoder_log_level(): def test_record_cancel(tmp_path): bag_path = str(tmp_path / 'test_record_cancel') storage_options, converter_options = get_rosbag_options(bag_path) +======= +@pytest.mark.parametrize('storage_id', TESTED_STORAGE_IDS) +def test_record_cancel(tmp_path, storage_id): + bag_path = tmp_path / 'test_record_cancel' + storage_options, converter_options = get_rosbag_options(str(bag_path), storage_id) +>>>>>>> 66af3999 (Fix for false negative tests in rosbag2_py (#1592)) recorder = rosbag2_py.Recorder() @@ -102,8 +112,21 @@ def test_record_cancel(tmp_path): recorder.cancel() +<<<<<<< HEAD metadata_path = Path(bag_path) / 'metadata.yaml' db3_path = Path(bag_path) / 'test_record_cancel_0.db3' assert wait_for(lambda: metadata_path.is_file() and db3_path.is_file(), timeout=rclpy.duration.Duration(seconds=3)) record_thread.join() +======= + metadata_io = rosbag2_py.MetadataIo() + assert wait_for(lambda: metadata_io.metadata_file_exists(str(bag_path)), + timeout=rclpy.duration.Duration(seconds=3)) + record_thread.join() + + metadata = metadata_io.read_metadata(str(bag_path)) + assert len(metadata.relative_file_paths) + storage_path = bag_path / metadata.relative_file_paths[0] + assert wait_for(lambda: storage_path.is_file(), + timeout=rclpy.duration.Duration(seconds=3)) +>>>>>>> 66af3999 (Fix for false negative tests in rosbag2_py (#1592))