Skip to content

Commit

Permalink
Fix for false negative tests in rosbag2_py (#1592)
Browse files Browse the repository at this point in the history
* 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 <michael.orlov@apex.ai>

* Address review comments in regards bag_path optimization

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

---------

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
(cherry picked from commit 66af399)

# Conflicts:
#	rosbag2_py/test/test_transport.py
  • Loading branch information
MichaelOrlov authored and mergify[bot] committed Jun 4, 2024
1 parent 44bfa78 commit 514650b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rosbag2_py/test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def wait_for(
if clock.now() - start > timeout:
return False
time.sleep(sleep_time)
return True
return True
13 changes: 9 additions & 4 deletions rosbag2_py/test/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import datetime
from pathlib import Path
import threading

from common import get_rosbag_options, wait_for
Expand Down Expand Up @@ -64,8 +63,8 @@ def test_recoder_log_level():

@pytest.mark.parametrize('storage_id', TESTED_STORAGE_IDS)
def test_record_cancel(tmp_path, storage_id):
bag_path = str(tmp_path / 'test_record_cancel')
storage_options, converter_options = get_rosbag_options(bag_path, storage_id)
bag_path = tmp_path / 'test_record_cancel'
storage_options, converter_options = get_rosbag_options(str(bag_path), storage_id)

recorder = rosbag2_py.Recorder()

Expand Down Expand Up @@ -98,12 +97,18 @@ def test_record_cancel(tmp_path, storage_id):
recorder.cancel()

metadata_io = rosbag2_py.MetadataIo()
assert wait_for(lambda: metadata_io.metadata_file_exists(bag_path),
assert wait_for(lambda: metadata_io.metadata_file_exists(str(bag_path)),
timeout=rclpy.duration.Duration(seconds=3))
record_thread.join()

<<<<<<< HEAD
metadata = metadata_io.read_metadata(bag_path)
assert(len(metadata.relative_file_paths))
storage_path = Path(metadata.relative_file_paths[0])
=======
metadata = metadata_io.read_metadata(str(bag_path))
assert len(metadata.relative_file_paths)
storage_path = bag_path / metadata.relative_file_paths[0]
>>>>>>> 66af3999 (Fix for false negative tests in rosbag2_py (#1592))
assert wait_for(lambda: storage_path.is_file(),
timeout=rclpy.duration.Duration(seconds=3))

0 comments on commit 514650b

Please sign in to comment.