Skip to content

Commit

Permalink
test(nebula_ros): fix what is probably a timing issue by explicitly w…
Browse files Browse the repository at this point in the history
…aiting for known-good console output

Signed-off-by: Max SCHMELLER <[email protected]>
  • Loading branch information
mojomex committed Feb 4, 2025
1 parent 324d721 commit 4f1cf58
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions nebula_ros/test/smoke_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
import unittest

from launch import LaunchContext
Expand All @@ -11,7 +10,6 @@
import launch_testing.actions
import launch_testing.asserts
import pytest
import rclpy


def resolve_launch_file(context: LaunchContext, *args, **kwargs):
Expand All @@ -29,25 +27,17 @@ def resolve_launch_file(context: LaunchContext, *args, **kwargs):
@pytest.mark.launch_test
def generate_test_description():
return LaunchDescription(
[OpaqueFunction(function=resolve_launch_file), launch_testing.actions.ReadyToTest()]
[
OpaqueFunction(function=resolve_launch_file),
launch_testing.actions.ReadyToTest(),
]
)


class DummyTest(unittest.TestCase):
def test_wait_for_node_ready(self):
"""Waiting for the node coming online."""
rclpy.init()
test_node = rclpy.create_node("test_node")
# Wait until both dummy node "test_node" and real tested node are registered and then kill
# both of them, if tested node does not register within `timeout` seconds test will fail
start_time = time.time()
timeout = 2 # seconds
timeout_msg = "Smoke test timeout has been exceeded ({}s)".format(timeout)
print("waiting for nodes to be ready")
while len(test_node.get_node_names()) < 2:
assert time.time() - start_time < timeout, timeout_msg
time.sleep(0.1)
rclpy.shutdown()
class TestCorrectStartup(unittest.TestCase):
def test_wait_for_startup_then_shutdown(self):
self.proc_output: launch_testing.ActiveIoHandler
self.proc_output.assertWaitFor("Wrapper=OK", timeout=2)


@launch_testing.post_shutdown_test()
Expand Down

0 comments on commit 4f1cf58

Please sign in to comment.