Skip to content

Commit

Permalink
Fix test_not_lose_callback() test to destroy entities properly
Browse files Browse the repository at this point in the history
EventsExecutor was exploding because the test was leaving destroyed entities in the node by using an
incorrect API to destroy them.

Signed-off-by: Brad Martin <[email protected]>
  • Loading branch information
Brad Martin committed Jan 21, 2025
1 parent 3502872 commit 4dd05c6
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions rclpy/test/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,37 +651,37 @@ def test_multi_threaded_spin_once_until_future(self) -> None:

def test_not_lose_callback(self) -> None:
self.assertIsNotNone(self.node.handle)
# TODO(bmartin427) EventsExecutor has some kind of explosion here I haven't figured out yet
executor = SingleThreadedExecutor(context=self.context)
for cls in [SingleThreadedExecutor, EventsExecutor]:
executor = cls(context=self.context)

callback_group = ReentrantCallbackGroup()
callback_group = ReentrantCallbackGroup()

cli = self.node.create_client(
srv_type=Empty, srv_name='test_service', callback_group=callback_group)
cli = self.node.create_client(
srv_type=Empty, srv_name='test_service', callback_group=callback_group)

async def timer1_callback() -> None:
timer1.cancel()
await cli.call_async(Empty.Request())
async def timer1_callback() -> None:
timer1.cancel()
await cli.call_async(Empty.Request())

timer1 = self.node.create_timer(0.5, timer1_callback, callback_group)
timer1 = self.node.create_timer(0.5, timer1_callback, callback_group)

count = 0
count = 0

def timer2_callback() -> None:
nonlocal count
count += 1
timer2 = self.node.create_timer(1.5, timer2_callback, callback_group)
def timer2_callback() -> None:
nonlocal count
count += 1
timer2 = self.node.create_timer(1.5, timer2_callback, callback_group)

executor.add_node(self.node)
future = Future(executor=executor)
executor.spin_until_future_complete(future, 4)
executor.add_node(self.node)
future = Future[None](executor=executor)
executor.spin_until_future_complete(future, 4)

assert count == 2
assert count == 2

executor.shutdown()
timer2.destroy()
timer1.destroy()
cli.destroy()
executor.shutdown()
self.node.destroy_timer(timer2)
self.node.destroy_timer(timer1)
self.node.destroy_client(cli)


if __name__ == '__main__':
Expand Down

0 comments on commit 4dd05c6

Please sign in to comment.