Skip to content

Commit

Permalink
Spin for a specific time instead of specific number of spin iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Jan 20, 2025
1 parent 65cf834 commit e31b6a6
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions rosbridge_library/test/capabilities/test_service_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ def test_call_advertised_service(self):
)
Thread(target=self.call_service.call_service, args=(call_msg,)).start()

loop_iterations = 0
start_time = time.monotonic()
while self.received_message is None:
rclpy.spin_once(self.node, timeout_sec=0.1)
time.sleep(0.1)
loop_iterations += 1
if loop_iterations > 4:
if time.monotonic() - start_time > 0.3:
self.fail("Timed out waiting for service call message.")

self.assertFalse(self.received_message is None)
Expand All @@ -141,12 +139,10 @@ def test_call_advertised_service(self):
self.received_message = None
self.response.service_response(response_msg)

loop_iterations = 0
start_time = time.monotonic()
while self.received_message is None:
rclpy.spin_once(self.node, timeout_sec=0.1)
time.sleep(0.5)
loop_iterations += 1
if loop_iterations > 4:
if time.monotonic() - start_time > 0.3:
self.fail("Timed out waiting for service response message.")

self.assertFalse(self.received_message is None)
Expand Down Expand Up @@ -182,12 +178,10 @@ def test_unadvertise_with_live_request(self):
self.received_message = None
Thread(target=self.call_service.call_service, args=(call_msg,)).start()

loop_iterations = 0
start_time = time.monotonic()
while self.received_message is None:
rclpy.spin_once(self.node, timeout_sec=0.1)
time.sleep(0.5)
loop_iterations += 1
if loop_iterations > 3:
if time.monotonic() - start_time > 0.3:
self.fail("Timed out waiting for service call message.")

self.assertFalse(self.received_message is None)
Expand All @@ -203,12 +197,10 @@ def test_unadvertise_with_live_request(self):
self.unadvertise.unadvertise_service(unadvertise_msg)

with self.assertRaises(RuntimeError) as context:
loop_iterations = 0
start_time = time.monotonic()
while self.received_message is None:
rclpy.spin_once(self.node, timeout_sec=0.1)
time.sleep(0.5)
loop_iterations += 1
if loop_iterations > 3:
if time.monotonic() - start_time > 0.3:
self.fail("Timed out waiting for unadvertise service message.")

self.assertTrue(f"Service {service_path} was unadvertised" in context.exception)
Expand Down

0 comments on commit e31b6a6

Please sign in to comment.