@@ -452,7 +452,11 @@ def timer_callback() -> None:
452452 timer = self .node .create_timer (0.003 , timer_callback )
453453
454454 # Timeout
455+ < << << << HEAD
455456 future = Future ()
457+ == == == =
458+ future = executor .create_future ()
459+ >> >> >> > bcdd663 (Feature : add executor .create_future () (#1495))
456460 self .assertFalse (future .done ())
457461 start = time .perf_counter ()
458462 executor .spin_until_future_complete (future = future , timeout_sec = 0.1 )
@@ -479,7 +483,11 @@ def set_future_result(future):
479483 future .set_result ('finished' )
480484
481485 # Future complete timeout_sec > 0
486+ << < << << HEAD
482487 future = Future ()
488+ == == == =
489+ future = executor .create_future ()
490+ >> > >> >> bcdd663 (Feature : add executor .create_future () (#1495))
483491 self .assertFalse (future .done ())
484492 t = threading .Thread (target = lambda : set_future_result (future ))
485493 t .start ()
@@ -488,7 +496,7 @@ def set_future_result(future):
488496 self .assertEqual (future .result (), 'finished' )
489497
490498 # Future complete timeout_sec = None
491- future = Future ()
499+ future = executor . create_future ()
492500 self .assertFalse (future .done ())
493501 t = threading .Thread (target = lambda : set_future_result (future ))
494502 t .start ()
@@ -497,7 +505,7 @@ def set_future_result(future):
497505 self .assertEqual (future .result (), 'finished' )
498506
499507 # Future complete timeout < 0
500- future = Future ()
508+ future = executor . create_future ()
501509 self .assertFalse (future .done ())
502510 t = threading .Thread (target = lambda : set_future_result (future ))
503511 t .start ()
@@ -519,7 +527,11 @@ def timer_callback() -> None:
519527 timer = self .node .create_timer (0.003 , timer_callback )
520528
521529 # Do not wait timeout_sec = 0
530+ << < << << HEAD
522531 future = Future ()
532+ == == == =
533+ future = executor .create_future ()
534+ >> > >> >> bcdd663 (Feature : add executor .create_future () (#1495))
523535 self .assertFalse (future .done ())
524536 executor .spin_until_future_complete (future = future , timeout_sec = 0 )
525537 self .assertFalse (future .done ())
@@ -602,7 +614,11 @@ def test_single_threaded_spin_once_until_future(self):
602614 with self .subTest (cls = cls ):
603615 executor = cls (context = self .context )
604616
617+ << < << << HEAD
605618 future = Future (executor = executor )
619+ == == == =
620+ future = executor .create_future ()
621+ >> > >> >> bcdd663 (Feature : add executor .create_future () (#1495))
606622
607623 # Setup a thread to spin_once_until_future_complete, which will spin
608624 # for a maximum of 10 seconds.
@@ -630,7 +646,11 @@ def test_multi_threaded_spin_once_until_future(self):
630646 self .assertIsNotNone (self .node .handle )
631647 executor = MultiThreadedExecutor (context = self .context )
632648
649+ << < << << HEAD
633650 future = Future (executor = executor )
651+ == == == =
652+ future : Future [bool ] = executor .create_future ()
653+ >> > >> >> bcdd663 (Feature : add executor .create_future () (#1495))
634654
635655 # Setup a thread to spin_once_until_future_complete, which will spin
636656 # for a maximum of 10 seconds.
@@ -679,7 +699,11 @@ def timer2_callback() -> None:
679699 timer2 = self .node .create_timer (1.5 , timer2_callback , callback_group )
680700
681701 executor .add_node (self .node )
702+ << < << << HEAD
682703 future = Future (executor = executor )
704+ == == == =
705+ future = executor .create_future ()
706+ >> > >> >> bcdd663 (Feature : add executor .create_future () (#1495))
683707 executor .spin_until_future_complete (future , 4 )
684708
685709 assert count == 2
@@ -689,6 +713,17 @@ def timer2_callback() -> None:
689713 self .node .destroy_timer (timer1 )
690714 self .node .destroy_client (cli )
691715
716+ def test_create_future_returns_future_with_executor_attached (self ) - > None :
717+ self .assertIsNotNone (self .node .handle )
718+ for cls in [SingleThreadedExecutor , MultiThreadedExecutor , EventsExecutor ]:
719+ with self .subTest (cls = cls ):
720+ executor = cls (context = self .context )
721+ try :
722+ fut = executor .create_future ()
723+ self .assertEqual (executor , fut ._executor ())
724+ finally :
725+ executor .shutdown ()
726+
692727
693728if __name__ == '__main__' :
694729 unittest .main ()
0 commit comments