@@ -856,6 +856,75 @@ def call_soon(self, callback, *args, context=None):
856856 self .run_briefly ()
857857 self .assertEqual (bag , [42 ])
858858
859+ def test_set_result_uses_private_call_soon_on_subclass_loop (self ):
860+ bag = []
861+ base_loop_cls = type (self .loop )
862+
863+ class CountingLoop (base_loop_cls ):
864+ def __init__ (self ):
865+ super ().__init__ ()
866+ self .private_calls = []
867+
868+ def _call_soon (self , callback , args , context ):
869+ self .private_calls .append ((callback , args , context ))
870+ return super ()._call_soon (callback , args , context )
871+
872+ old_loop = self .loop
873+ loop = CountingLoop ()
874+ self .loop = loop
875+ self .addCleanup (setattr , self , 'loop' , old_loop )
876+ self .addCleanup (loop .close )
877+
878+ f = self ._new_future ()
879+ cb = self ._make_callback (bag , 42 )
880+ f .add_done_callback (cb )
881+ f .set_result ('foo' )
882+
883+ self .assertEqual (len (loop .private_calls ), 1 )
884+ callback , args , context = loop .private_calls [0 ]
885+ self .assertIs (callback , cb )
886+ self .assertEqual (args , (f ,))
887+ self .assertIsNotNone (context )
888+
889+ self .run_briefly ()
890+ self .assertEqual (bag , [42 ])
891+
892+ def test_set_result_uses_instance_call_soon_shadow (self ):
893+ bag = []
894+ base_loop_cls = type (self .loop )
895+
896+ class CountingLoop (base_loop_cls ):
897+ pass
898+
899+ old_loop = self .loop
900+ loop = CountingLoop ()
901+ self .loop = loop
902+ self .addCleanup (setattr , self , 'loop' , old_loop )
903+ self .addCleanup (loop .close )
904+
905+ base_call_soon = base_loop_cls .call_soon
906+ calls = []
907+
908+ def call_soon (callback , * args , context = None ):
909+ calls .append ((callback , args , context ))
910+ return base_call_soon (loop , callback , * args , context = context )
911+
912+ loop .call_soon = call_soon
913+
914+ f = self ._new_future ()
915+ cb = self ._make_callback (bag , 42 )
916+ f .add_done_callback (cb )
917+ f .set_result ('foo' )
918+
919+ self .assertEqual (len (calls ), 1 )
920+ callback , args , context = calls [0 ]
921+ self .assertIs (callback , cb )
922+ self .assertEqual (args , (f ,))
923+ self .assertIsNotNone (context )
924+
925+ self .run_briefly ()
926+ self .assertEqual (bag , [42 ])
927+
859928 def test_callbacks_remove_first_callback (self ):
860929 bag = []
861930 f = self ._new_future ()
0 commit comments