Skip to content

Commit cb2e8bb

Browse files
committed
Add a test for resuming coroutine
Signed-off-by: Błażej Sowa <[email protected]>
1 parent 3129161 commit cb2e8bb

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

rclpy/test/test_executor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,29 @@ async def coroutine():
317317
self.assertTrue(future.cancelled())
318318
self.assertEqual(None, future.result())
319319

320+
def test_create_task_coroutine_wake_from_another_thread(self) -> None:
321+
self.assertIsNotNone(self.node.handle)
322+
323+
for cls in [SingleThreadedExecutor, MultiThreadedExecutor]:
324+
with self.subTest(cls=cls):
325+
executor = cls(context=self.context)
326+
thread_future = Future()
327+
328+
async def coroutine():
329+
await thread_future
330+
331+
def future_thread():
332+
threading.Event().wait(0.1) # Simulate some work
333+
thread_future.set_result(None)
334+
335+
t = threading.Thread(target=future_thread)
336+
t.start()
337+
338+
coroutine_future = executor.create_task(coroutine)
339+
executor.spin_until_future_complete(coroutine_future, timeout_sec=1.0)
340+
341+
self.assertTrue(coroutine_future.done())
342+
320343
def test_create_task_normal_function(self) -> None:
321344
self.assertIsNotNone(self.node.handle)
322345
for cls in [SingleThreadedExecutor, EventsExecutor]:

0 commit comments

Comments
 (0)