@@ -494,7 +494,7 @@ def timer_callback() -> None:
494494 timer = self .node .create_timer (0.003 , timer_callback )
495495
496496 # Timeout
497- future = Future [ None ] ()
497+ future = executor . create_future ()
498498 self .assertFalse (future .done ())
499499 start = time .perf_counter ()
500500 executor .spin_until_future_complete (future = future , timeout_sec = 0.1 )
@@ -521,7 +521,7 @@ def set_future_result(future: Future[str]) -> None:
521521 future .set_result ('finished' )
522522
523523 # Future complete timeout_sec > 0
524- future = Future [ str ] ()
524+ future = executor . create_future ()
525525 self .assertFalse (future .done ())
526526 t = threading .Thread (target = lambda : set_future_result (future ))
527527 t .start ()
@@ -530,7 +530,7 @@ def set_future_result(future: Future[str]) -> None:
530530 self .assertEqual (future .result (), 'finished' )
531531
532532 # Future complete timeout_sec = None
533- future = Future ()
533+ future = executor . create_future ()
534534 self .assertFalse (future .done ())
535535 t = threading .Thread (target = lambda : set_future_result (future ))
536536 t .start ()
@@ -539,7 +539,7 @@ def set_future_result(future: Future[str]) -> None:
539539 self .assertEqual (future .result (), 'finished' )
540540
541541 # Future complete timeout < 0
542- future = Future ()
542+ future = executor . create_future ()
543543 self .assertFalse (future .done ())
544544 t = threading .Thread (target = lambda : set_future_result (future ))
545545 t .start ()
@@ -561,7 +561,7 @@ def timer_callback() -> None:
561561 timer = self .node .create_timer (0.003 , timer_callback )
562562
563563 # Do not wait timeout_sec = 0
564- future = Future [ None ] ()
564+ future = executor . create_future ()
565565 self .assertFalse (future .done ())
566566 executor .spin_until_future_complete (future = future , timeout_sec = 0 )
567567 self .assertFalse (future .done ())
@@ -644,7 +644,7 @@ def test_single_threaded_spin_once_until_future(self) -> None:
644644 with self .subTest (cls = cls ):
645645 executor = cls (context = self .context )
646646
647- future = Future [ bool ]( executor = executor )
647+ future = executor . create_future ( )
648648
649649 # Setup a thread to spin_once_until_future_complete, which will spin
650650 # for a maximum of 10 seconds.
@@ -672,7 +672,7 @@ def test_multi_threaded_spin_once_until_future(self) -> None:
672672 self .assertIsNotNone (self .node .handle )
673673 executor = MultiThreadedExecutor (context = self .context )
674674
675- future : Future [bool ] = Future ( executor = executor )
675+ future : Future [bool ] = executor . create_future ( )
676676
677677 # Setup a thread to spin_once_until_future_complete, which will spin
678678 # for a maximum of 10 seconds.
@@ -721,7 +721,7 @@ def timer2_callback() -> None:
721721 timer2 = self .node .create_timer (1.5 , timer2_callback , callback_group )
722722
723723 executor .add_node (self .node )
724- future = Future [ None ]( executor = executor )
724+ future = executor . create_future ( )
725725 executor .spin_until_future_complete (future , 4 )
726726
727727 assert count == 2
@@ -731,6 +731,17 @@ def timer2_callback() -> None:
731731 self .node .destroy_timer (timer1 )
732732 self .node .destroy_client (cli )
733733
734+ def test_create_future_returns_future_with_executor_attached (self ) -> None :
735+ self .assertIsNotNone (self .node .handle )
736+ for cls in [SingleThreadedExecutor , MultiThreadedExecutor , EventsExecutor ]:
737+ with self .subTest (cls = cls ):
738+ executor = cls (context = self .context )
739+ try :
740+ fut = executor .create_future ()
741+ self .assertEqual (executor , fut ._executor ())
742+ finally :
743+ executor .shutdown ()
744+
734745
735746if __name__ == '__main__' :
736747 unittest .main ()
0 commit comments