Skip to content

Commit

Permalink
Moves to asserting expected output match outside of the process context
Browse files Browse the repository at this point in the history
to account for cases where wait_for_output is maybe called after the
expected output is already printed.

Signed-off-by: Jaison Titus <[email protected]>
  • Loading branch information
jaisontj committed Sep 18, 2020
1 parent e2ce040 commit 8ebcb5f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ros2bag/test/test_record_qos_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
PROFILE_PATH = Path(__file__).parent / 'resources'
TEST_NODE = 'ros2bag_record_qos_profile_test_node'
TEST_NAMESPACE = 'ros2bag_record_qos_profile'
ERROR_STRING = r'\[ERROR] \[ros2bag]:'


@pytest.mark.rostest
Expand Down Expand Up @@ -84,12 +83,13 @@ def test_qos_simple(self):
expected_string_regex = re.compile(
r'\[rosbag2_storage]: Opened database .* for READ_WRITE')
with self.launch_bag_command(arguments=arguments) as bag_command:
condition_result = bag_command.wait_for_output(
bag_command.wait_for_output(
condition=lambda output: expected_string_regex.search(output) is not None,
timeout=5)
assert condition_result, print('ros2bag CLI did not produce the expected output')
bag_command.wait_for_shutdown(timeout=5)
assert bag_command.terminated
matches = expected_string_regex.search(bag_command.output)
assert matches, print('ros2bag CLI did not produce the expected output')

def test_incomplete_qos_profile(self):
profile_path = PROFILE_PATH / 'incomplete_qos_profile.yaml'
Expand All @@ -99,12 +99,13 @@ def test_incomplete_qos_profile(self):
expected_string_regex = re.compile(
r'\[rosbag2_storage]: Opened database .* for READ_WRITE')
with self.launch_bag_command(arguments=arguments) as bag_command:
condition_result = bag_command.wait_for_output(
bag_command.wait_for_output(
condition=lambda output: expected_string_regex.search(output) is not None,
timeout=5)
assert condition_result, print('ros2bag CLI did not produce the expected output')
bag_command.wait_for_shutdown(timeout=5)
assert bag_command.terminated
matches = expected_string_regex.search(bag_command.output)
assert matches, print('ros2bag CLI did not produce the expected output')

def test_incomplete_qos_duration(self):
profile_path = PROFILE_PATH / 'incomplete_qos_duration.yaml'
Expand All @@ -114,12 +115,13 @@ def test_incomplete_qos_duration(self):
expected_string_regex = re.compile(
r'\[ERROR] \[ros2bag]: Time overrides must include both')
with self.launch_bag_command(arguments=arguments) as bag_command:
condition_result = bag_command.wait_for_output(
bag_command.wait_for_output(
condition=lambda output: expected_string_regex.search(output) is not None,
timeout=5)
assert condition_result, print('ros2bag CLI did not produce the expected output')
bag_command.wait_for_shutdown(timeout=5)
assert bag_command.terminated
matches = expected_string_regex.search(bag_command.output)
assert matches, print('ros2bag CLI did not produce the expected output')
assert bag_command.exit_code != launch_testing.asserts.EXIT_OK

def test_nonexistent_qos_profile(self):
Expand All @@ -130,10 +132,11 @@ def test_nonexistent_qos_profile(self):
expected_string_regex = re.compile(
r'ros2 bag record: error: argument --qos-profile-overrides-path: can\'t open')
with self.launch_bag_command(arguments=arguments) as bag_command:
condition_result = bag_command.wait_for_output(
bag_command.wait_for_output(
condition=lambda output: expected_string_regex.search(output) is not None,
timeout=5)
assert condition_result, print('ros2bag CLI did not produce the expected output')
bag_command.wait_for_shutdown(timeout=5)
assert bag_command.terminated
matches = expected_string_regex.search(bag_command.output)
assert matches, print('ros2bag CLI did not produce the expected output')
assert bag_command.exit_code != launch_testing.asserts.EXIT_OK

0 comments on commit 8ebcb5f

Please sign in to comment.