
    ^h:m                     b   S SK r S SKJr  S SKJr  S SKJr  S SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKrS SKrS SKrS SKJr  S SKrS SKJr  S SKJr  S SKJrJrJr  S S	KJr  S S
KJrJrJrJ r J!r!  S SK"J#r#J$r$  S SK%J&r&  S SK'r'\'RP                  (       a  S SK'J)r)   " S S\5      r* " S S\RV                  5      r, " S S\5      r- " S S\5      r. " S S\RV                  5      r/ " S S\RV                  5      r0 " S S\5      r1 " S S\RV                  5      r2\3S:X  a  \Rh                  " 5         gg)    N)ThreadPoolExecutor)futures)	Generator)mock)
native_str)gen)IOLoopTimeoutErrorPeriodicCallback)app_log)AsyncTestCasebind_unused_port	ExpectLoggen_testsetup_with_context_manager)ignore_deprecationskipIfNonUnix)Future)Listc                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 r\S 5       rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r\S 5       r\\S 5       5       r S r!Sr"g) 
TestIOLoop(   c                   ^^ SU l         U R                  nU mUR                  mUU4S jn[        R                  " X!5      Ul        UR                  S 5        UR                  S 5        UR                  [        R                  " SS9UR                  5        UR                  5         U R                  U R                   S5        g )Nr   c                 H   > T=R                   S-  sl         T" U/UQ70 UD6  g N   calls)selfcallbackargskwargsold_add_callbacktests       R/home/james-whalen/.local/lib/python3.13/site-packages/tornado/test/ioloop_test.pyadd_callbackBTestIOLoop.test_add_callback_return_sequence.<locals>.add_callback1   s"    JJ!OJX777    c                      0 $ N r+   r(   r%   <lambda>>TestIOLoop.test_add_callback_return_sequence.<locals>.<lambda>6       "r(   c                      / $ r*   r+   r+   r(   r%   r,   r-   7   r.   r(   2   )milliseconds
   )r   io_loopr&   types
MethodTypeadd_timeoutdatetime	timedeltastopstart
assertLess)r   loopr&   r#   r$   s      @@r%   !test_add_callback_return_sequence,TestIOLoop.test_add_callback_return_sequence)   s    
||,,	8 ",,\@*%*%++<diiH



B'r(   c                 <  ^ ^ U 4S jmUU 4S jnT R                   R                  T R                   R                  5       U5        T R                  5         T R	                  [        R                  " 5       T R
                  SS9  T R                  T R                  5        g )Nc                  4   > ST l         T R                  5         g NT)calledr9   r   s   r%   r    5TestIOLoop.test_add_callback_wakeup.<locals>.callback?   s    DKIIKr(   c                  ~   > STl         TR                  R                  T 5        [        R                  " 5       Tl        g NF)rB   r3   r&   time
start_time)r    r   s   r%   schedule_callback>TestIOLoop.test_add_callback_wakeup.<locals>.schedule_callbackC   s)    DKLL%%h/"iikDOr(      )places)r3   r6   rG   waitassertAlmostEqualrH   
assertTruerB   )r   rI   r    s   ` @r%   test_add_callback_wakeup#TestIOLoop.test_add_callback_wakeup<   si    		* 	  !2!2!46GH		tyy{DOOAF$r(   c                 ,  ^  U 4S jn[         R                  " US9nT R                  R                  UR                  5        T R                  5         [        R                  " 5       T R                  -
  nT R                  US5        UR                  5         g )Nc                     > [         R                  " S5        [         R                   " 5       T l        T R                  R	                  T R
                  5        g )N{Gz?)rG   sleep	stop_timer3   r&   r9   rC   s   r%   target@TestIOLoop.test_add_callback_wakeup_other_thread.<locals>.targetO   s2    JJt!YY[DNLL%%dii0r(   rW   皙?)
	threadingThreadr3   r&   r:   rM   rG   rV   r;   join)r   rW   threaddeltas   `   r%   %test_add_callback_wakeup_other_thread0TestIOLoop.test_add_callback_wakeup_other_threadN   sd    	1 !!0!!&,,/				dnn,s#r(   c                     U R                   R                  [        R                  " SS9U R                  5        U R                  5         g )Nr   )microseconds)r3   r6   r7   r8   r9   rM   rC   s    r%   test_add_timeout_timedelta%TestIOLoop.test_add_timeout_timedelta\   s.      !3!3!CTYYO		r(   c                    [        5       u  p U R                  R                  UR                  5       S [        R
                  5        U R                  [        U R                  R                  UR                  5       S [        R
                  5        U R                  R                  UR                  5       5        UR                  5         g ! U R                  R                  UR                  5       5        UR                  5         f = f)Nc                     g r*   r+   fdeventss     r%   r,   .TestIOLoop.test_multiple_add.<locals>.<lambda>d   s    $r(   c                     g r*   r+   rh   s     r%   r,   rk   l   s    4r(   )
r   r3   add_handlerfilenor	   READassertRaises	Exceptionremove_handlercloser   sockports      r%   test_multiple_addTestIOLoop.test_multiple_add`   s    %'
	LL$$6
 ((' LL''6JJL LL''6JJLs   BC ;Dc                     [        5       u  p U R                  R                  UR                  5       5        UR	                  5         g ! UR	                  5         f = fr*   )r   r3   rr   rn   rs   rt   s      r%   test_remove_without_add"TestIOLoop.test_remove_without_adds   s>     &'
	LL''6JJLDJJLs   )A Ac                     [        5          U R                  R                  U R                  5        S S S 5        U R	                  5         g ! , (       d  f       N= fr*   )r   r3   add_callback_from_signalr9   rM   rC   s    r%   test_add_callback_from_signal(TestIOLoop.test_add_callback_from_signal|   s7      !LL11$))< "		 "!s   &A


Ac                 0   [        SS9n[        R                  " UR                  S9nUR                  5         [	        5          UR                  UR                  5        S S S 5        UR                  5         UR                  5         g ! , (       d  f       N/= f)NFmake_currentrY   )	r	   r[   r\   r:   r   r}   r9   r]   rs   )r   other_ioloopr^   s      r%   *test_add_callback_from_signal_other_thread5TestIOLoop.test_add_callback_from_signal_other_thread   sj     51!!););<!11,2C2CD " "!s   B
Bc                   ^^ [         R                  " 5       mUU4S jn[        SS9m[         R                  " US9nUR	                  5         TR                  5         [        S5       H  nTR                  S 5        M     g )Nc                     > TR                  TR                  5        TR                  5         T R                  5         TR	                  SS9  g )NTall_fds)r&   r9   r:   setrs   )closingr   s   r%   rW   :TestIOLoop.test_add_callback_while_closing.<locals>.target   s=    %%l&7&78 KKMt,r(   Fr   rY     c                      g r*   r+   r+   r(   r%   r,   <TestIOLoop.test_add_callback_while_closing.<locals>.<lambda>   s    dr(   )r[   Eventr	   r\   r:   rM   ranger&   )r   rW   r^   ir   r   s       @@r%   test_add_callback_while_closing*TestIOLoop.test_add_callback_while_closing   s`     //#	- 51!!0tA%%l3 r(   c                 \  ^  [         R                  " 5       u  p U 4S jnT R                  R                  UR	                  5       U[
        R                  5        T R                  R                  T R                  R                  5       S-   [        R                  " UR                  S5      5        T R                  5         T R                  R                  UR	                  5       5        UR                  5         UR                  5         g ! UR                  5         UR                  5         f = f)Nc                 f   > TR                  U[        R                  5        TR                  5         g r*   )assertEqualr	   ro   r9   )ri   rj   r   s     r%   handler5TestIOLoop.test_read_while_writeable.<locals>.handler   s       5		r(   rT   s   asdf)socket
socketpairr3   rm   rn   r	   ro   r6   rG   	functoolspartialsendrM   rr   rs   )r   clientserverr   s   `   r%   test_read_while_writeable$TestIOLoop.test_read_while_writeable   s    
  **,	 LL$$V]]_gv{{KLL$$!!#d*I,=,=fkk7,S IIKLL''8LLNLLN LLNLLNs   CD	 	"D+c                     U R                   R                  U R                   R                  5       U R                  5      nU R	                  5         U R                   R                  U5        g r*   )r3   r6   rG   r9   rM   remove_timeoutr   handles     r%   test_remove_timeout_after_fire)TestIOLoop.test_remove_timeout_after_fire   sD    ))$,,*;*;*=tyyI		##F+r(   c                 .  ^  [        S5       HV  nT R                  R                  T R                  R                  5       S-   S 5      nT R                  R	                  U5        MX     T R                  R                  U 4S j5        T R                  5         g )Ni  i  c                      g r*   r+   r+   r(   r%   r,   8TestIOLoop.test_remove_timeout_cleanup.<locals>.<lambda>   s    SWr(   c                  N   > T R                   R                  T R                  5      $ r*   r3   r&   r9   rC   s   r%   r,   r      s    $,,*C*CDII*Nr(   )r   r3   r6   rG   r   r&   rM   )r   r   timeouts   `  r%   test_remove_timeout_cleanup&TestIOLoop.test_remove_timeout_cleanup   sk     tAll..t||/@/@/BT/I<XGLL''0  	!!"NO		r(   c                   ^ ^^ SS/mT R                   R                  5       nUU U4S jnT R                   R                  US-   U5        U4S jnT R                   R                  US-   U5      mT R                   R                  US-   T R                  5        [        R                  " S5        T R                  5         T R                  TSS/5        g )NFc                  F   > ST S'   TR                   R                  T5        g NTr   )r3   r   )r   r   	t2_handles   r%   t17TestIOLoop.test_remove_timeout_from_timeout.<locals>.t1   s    E!HLL''	2r(   rT   c                     > ST S'   g )NTr   r+   r   s   r%   t27TestIOLoop.test_remove_timeout_from_timeout.<locals>.t2   s    E!Hr(   g{Gz?gQ?T)r3   rG   r6   r9   rU   rM   r   )r   nowr   r   r   r   s   `   @@r%    test_remove_timeout_from_timeout+TestIOLoop.test_remove_timeout_from_timeout   s    
 ll!	3 	  tR0	 LL,,S4Z<	  tTYY7

4		u.r(   c                 j   / nU R                   R                  U R                   R                  5       UR                  S5        U R                   R                  [        R
                  " SS9UR                  S5        U R                   R                  U R                   R                  5       UR                  S5        U R                   R                  SUR                  S5        U R                   R                  SU R                  5        U R                  5         U R                  [        U5      / SQ5        g )Nr   r   )secondsrK         )r   rK   r   r   )r3   r6   rG   appendr7   r8   call_at
call_laterr9   rM   r   sorted)r   resultss     r%   test_timeout_with_arguments&TestIOLoop.test_timeout_with_arguments   s      !2!2!4gnnaH  !3!3A!>PQRT\\..0'..!D7>>15499-		 	,7r(   c                     U R                   R                  U R                   R                  5       S 5      nU R                  U5        U R                   R	                  U5        g )Nc                      g r*   r+   r+   r(   r%   r,   4TestIOLoop.test_add_timeout_return.<locals>.<lambda>   s    tr(   )r3   r6   rG   assertIsNotNoner   r   s     r%   test_add_timeout_return"TestIOLoop.test_add_timeout_return   sG     ))$,,*;*;*=|LV$##F+r(   c                     U R                   R                  U R                   R                  5       S 5      nU R                  U5        U R                   R	                  U5        g )Nc                      g r*   r+   r+   r(   r%   r,   0TestIOLoop.test_call_at_return.<locals>.<lambda>   s    4r(   )r3   r   rG   r   r   r   s     r%   test_call_at_returnTestIOLoop.test_call_at_return   sE    %%dll&7&7&9<HV$##F+r(   c                     U R                   R                  SS 5      nU R                  U5        U R                   R                  U5        g )Nr   c                      g r*   r+   r+   r(   r%   r,   3TestIOLoop.test_call_later_return.<locals>.<lambda>   s    Dr(   )r3   r   r   r   r   s     r%   test_call_later_return!TestIOLoop.test_call_later_return   s8    ((L9V$##F+r(   c                    ^^  " S S5      n[        5       u  p#U" U5      m[        SS9mTR                  UU4S j5        TR                  SS9  U R	                  TR
                  5        g)	zWhen a file object is used instead of a numeric file descriptor,
the object should be closed (by IOLoop.close(all_fds=True),
not just the fd.
c                   &    \ rS rSrS rS rS rSrg)8TestIOLoop.test_close_file_object.<locals>.SocketWrapperi	  c                     Xl         SU l        g rF   )sockobjclosed)r   r   s     r%   __init__ATestIOLoop.test_close_file_object.<locals>.SocketWrapper.__init__
  s    &#r(   c                 6    U R                   R                  5       $ r*   )r   rn   rC   s    r%   rn   ?TestIOLoop.test_close_file_object.<locals>.SocketWrapper.fileno  s    ||**,,r(   c                 F    SU l         U R                  R                  5         g rA   )r   r   rs   rC   s    r%   rs   >TestIOLoop.test_close_file_object.<locals>.SocketWrapper.close  s    """$r(   )r   r   N)__name__
__module____qualname____firstlineno__r   rn   rs   __static_attributes__r+   r(   r%   SocketWrapperr   	  s    $-%r(   r   Fr   c                  H   > T R                  TS [        R                  5      $ )Nc                     g r*   r+   rh   s     r%   r,   ETestIOLoop.test_close_file_object.<locals>.<lambda>.<locals>.<lambda>  s    4r(   )rm   r	   ro   )r3   socket_wrappers   r%   r,   3TestIOLoop.test_close_file_object.<locals>.<lambda>  s    G'' 7r(   Tr   N)r   r	   run_syncrs   rO   r   )r   r   r   rv   r3   r   s       @@r%   test_close_file_object!TestIOLoop.test_close_file_object   sb    
	% 
	% )*&w/e,	

 	d#--.r(   c                   ^ ^^ [        5       u  mn/ mUU U4S jnT R                  R                  TU[        R                  5        [
        R                  " [        R                  " 5       5       nUR                  SU45        T R                  5         SSS5        T R                  R                  T5        T R                  R                  TR                  5       U[        R                  5        [
        R                  " [        R                  " 5       5       nUR                  SU45        T R                  5         SSS5        T R                  TS   T5        T R                  TS   TR                  5       5        T R                  R                  TR                  5       5        TR                  5         g! , (       d  f       GN*= f! , (       d  f       N= f)z>The handler callback receives the same fd object it passed in.c                    > TR                  U 5        TR                  5       u  p#UR                  5         TR                  5         g r*   )r   acceptrs   r9   )ri   rj   connaddrfdsr   server_socks       r%   handle_connectionGTestIOLoop.test_handler_callback_file_object.<locals>.handle_connection%  s0    JJrN$++-JDJJLIIKr(   z	127.0.0.1Nr   r   )r   r3   rm   r	   ro   
contextlibr   r   connectrM   rr   rn   assertIsr   rs   )r   rv   r   client_sockr   r   s   `   @@r%   !test_handler_callback_file_object,TestIOLoop.test_handler_callback_file_object   sG   ,.T	 	  .?M0Kd 34IIK 1 	##K0  !3!3!57H&++V0Kd 34IIK 1 	c!fk*Q!3!3!56##K$6$6$89 10
 10s   /$F6$G6
G
Gc                    [        5       u  pS nU R                  R                  X[        R                  5        U R                  [        5         U R                  R                  UR                  5       U[        R                  5        S S S 5        U R                  R                  UR                  5       5        UR                  5         g ! , (       d  f       NH= f)Nc                     g r*   r+   rh   s     r%   f+TestIOLoop.test_mixed_fd_fileobj.<locals>.f<  s    r(   )
r   r3   rm   r	   ro   rp   rq   rn   rr   rs   )r   r   rv   r  s       r%   test_mixed_fd_fileobj TestIOLoop.test_mixed_fd_fileobj9  s    ,.	 	  =y) LL$$[%7%7%91fkkJ * 	##K$6$6$89 *)s   :C
Cc                    ^ ^^ S/mS/mUUU 4S jnT R                   R                  U5        T R                  5         T R                  TS   5        T R	                  TS   5        g)z:Calling start() twice should raise an error, not deadlock.Fc                     >  TR                   R                  5         STS'   TR                  5         g ! [         a    ST S'    N"f = fr   )r3   r:   rq   r9   )got_exceptionreturned_from_startr   s   r%   r    +TestIOLoop.test_reentrant.<locals>.callbackL  sI    (""$)-#A& IIK  (#'a (s   3 AAr   N)r3   r&   rM   rO   assertFalse)r   r    r	  r
  s   ` @@r%   test_reentrantTestIOLoop.test_reentrantG  sY    $g	 	!!(+		a(),Q/0r(   c                     U R                   R                  S 5        U R                   R                  U R                  5        [        [        S5         U R                  5         SSS5        g! , (       d  f       g= f)z-Uncaught exceptions get logged by the IOLoop.c                      SS-  $ Nr   r   r+   r+   r(   r%   r,   3TestIOLoop.test_exception_logging.<locals>.<lambda>[      !a%r(   Exception in callbackN)r3   r&   r9   r   r   rM   rC   s    r%   test_exception_logging!TestIOLoop.test_exception_loggingY  sJ    !!-0!!$)),w 78IIK 988s   A,,
A:c                    ^  [         R                  U 4S j5       nT R                  R                  U5        [	        [
        S5         T R                  5         SSS5        g! , (       d  f       g= f)z:The IOLoop examines exceptions from Futures and logs them.c                  Z   > T R                   R                  T R                  5        SS-    g r  r   rC   s   r%   r    :TestIOLoop.test_exception_logging_future.<locals>.callbackc  s     LL%%dii0Er(   r  N)r   	coroutiner3   r&   r   r   rM   r   r    s   ` r%   test_exception_logging_future(TestIOLoop.test_exception_logging_future`  sO     
	 
	 	!!(+w 78IIK 988s   A  
A.c                    ^  U 4S jnT R                   R                  U5        [        [        S5         T R	                  5         SSS5        g! , (       d  f       g= f)z=The IOLoop examines exceptions from awaitables and logs them.c                     >#    T R                   R                  T R                   R                  T R                  5        SS-    g 7fr  r   rC   s   r%   r    ?TestIOLoop.test_exception_logging_native_coro.<locals>.callbacko  s1      LL%%dll&?&?KEs   AAr  N)r3   r&   r   r   rM   r  s   ` r%   "test_exception_logging_native_coro-TestIOLoop.test_exception_logging_native_corol  s<    	 	!!(+w 78IIK 988s   A
Ac                    U R                   R                  S 5        U R                   R                  U R                  5        [        [        S5         U R                  5         S S S 5        U R                   R                  S 5        U R                   R                  U R                  5        [        [        S5         U R                  5         S S S 5        g ! , (       d  f       Ny= f! , (       d  f       g = f)Nc                      SS-  $ r  r+   r+   r(   r%   r,   0TestIOLoop.test_spawn_callback.<locals>.<lambda>|  r  r(   r  c                      SS-  $ r  r+   r+   r(   r%   r,   r%    s    AEr(   )r3   r&   r9   r   r   rM   spawn_callbackrC   s    r%   test_spawn_callbackTestIOLoop.test_spawn_callbacky  s     	!!-0!!$)),w 78IIK 9 	##M2!!$)),w 78IIK 98 98 98s   C<C'
C$'
C5c                 x  ^ ^^^ [         R                  " 5       u  mm TR                  S5        TR                  S5        / mUUU U4S jnT R                  R	                  TUT R                  R
                  5        T R                  R	                  TUT R                  R
                  5        T R                  R                  ST R                  5        T R                  5         T R                  TS/5        TR                  5         TR                  5         g ! TR                  5         TR                  5         f = f)Ns   abcc                    > TR                  U R                  S5      5        U TL a  TR                  R                  T5        g TR                  R                  T5        g )Ni   )r   recvr3   rr   )ri   rj   chunksr   r   r   s     r%   handle_read@TestIOLoop.test_remove_handler_from_handler.<locals>.handle_read  sB    bggdm,<LL//7LL//7r(   rZ   )r   r   r   r3   rm   ro   r   r9   rM   r   rs   )r   r.  r-  r   r   s   ` @@@r%    test_remove_handler_from_handler+TestIOLoop.test_remove_handler_from_handler  s      **,	KKKK F8 8 LL$$V[$,,:K:KLLL$$V[$,,:K:KLLL##C3IIK VfX.LLNLLN LLNLLNs   CD "D9c           	   #      #    S n[         R                  " [        S5       Vs/ s H  o R                  R	                  S U5      PM      sn5      v   g s  snf 7f)Nc                  Z    [        S5       H  n [        SS9nUR                  5         M     g )Nr2   Fr   )r   r	   rs   )r   r<   s     r%   r  *TestIOLoop.test_init_close_race.<locals>.f  s#    2Y51

 r(   rK   )r   multir   r3   run_in_executor)r   r  r   s      r%   test_init_close_raceTestIOLoop.test_init_close_race  s@     	
 iiaQ155dA>QRRQs   !A%AAc                     [         R                  " 5       n[        USS9nUR                  UL d   eU R	                  [
        5         [        USS9  S S S 5        UR                  5         g ! , (       d  f       N= f)NF)asyncio_loopr   )asyncionew_event_loopr	   r:  rp   RuntimeErrorrs   )r   r:  r<   s      r%   test_explicit_asyncio_loop%TestIOLoop.test_explicit_asyncio_loop  sa    --/<eD  L000|,5A - 	

 -,s   A**
A8)rB   r   rH   rV   N)#r   r   r   r   r=   rP   r`   rd   rw   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r!  r(  r0  r   r7  r>  r   r+   r(   r%   r   r   (   s    (&%$&
4&  *,/.8,,
,
/@21$
  8 S  Sr(   r   c                   ,    \ rS rSrS rS rS rS rSrg)TestIOLoopCurrenti  c                 d    [        U [        5       5        S U l        [        R                  " 5         g r*   )r   r   r3   r	   clear_currentrC   s    r%   setUpTestIOLoopCurrent.setUp  s#    "4);)=>r(   c                 T    U R                   b  U R                   R                  5         g g r*   r3   rs   rC   s    r%   tearDownTestIOLoopCurrent.tearDown  s!    <<#LL  $r(   c                   ^  [        SS9T l        T R                  [         R                  " SS95        [	        S5       H  nU 4S jnT R                  R                  U5        T R                  R                  5         T R                  T R                  T R                  5        T R                  [         R                  " SS95        M     g )NFr   )instancer   c                     > [         R                  " 5       T l        T R                  c   eT R                  R	                  5         g r*   )r	   currentcurrent_io_loopr3   r9   rC   s   r%   r  -TestIOLoopCurrent.test_non_current.<locals>.f  s2    '-~~'7$||///!!#r(   )	r	   r3   assertIsNonerM  r   r&   r:   r   rN  )r   r   r  s   `  r%   test_non_current"TestIOLoopCurrent.test_non_current  s    51&..%89 qA$
 LL%%a(LL MM$..=fnne<= r(   c                 ~    [        SS9U l        U R                  U R                  [         R                  " 5       5        g )NTr   )r	   r3   r   rM  rC   s    r%   test_force_current$TestIOLoopCurrent.test_force_current  s'    40dllFNN$45r(   )rN  r3   N)	r   r   r   r   rD  rH  rQ  rT  r   r+   r(   r%   rA  rA    s    
!>&6r(   rA  c                   8   ^  \ rS rSrU 4S jr\S 5       rSrU =r$ )TestIOLoopCurrentAsynci  c                 J   > [         TU ]  5         [        U [        5       5        g r*   )superrD  r   r   )r   	__class__s    r%   rD  TestIOLoopCurrentAsync.setUp  s    "4);)=>r(   c              #      #    [        S5       nUR                  [        R                  5      v   S S S 5        g ! , (       d  f       g = f7fr   )r   submitr	   rC  )r   es     r%   test_clear_without_current1TestIOLoopCurrentAsync.test_clear_without_current  s1     
  "a((6//00 #""s   A
"9	A

AA
r+   )	r   r   r   r   rD  r   r_  r   __classcell__)rZ  s   @r%   rW  rW    s    ? 1 1r(   rW  c                   J    \ rS rSrS r\S 5       r\S 5       r\S 5       rSr	g)TestIOLoopFuturesi  c                 f  ^  [         R                  " S5       nS nT R                  R                  UR	                  U5      U 4S j5        T R                  5       nT R                  UR                  5       5        T R                  UR                  5       5        S S S 5        g ! , (       d  f       g = f)Nr   c                      g r*   r+   r+   r(   r%   dummy8TestIOLoopFutures.test_add_future_threads.<locals>.dummy  s    r(   c                 &   > TR                  U 5      $ r*   r9   )futurer   s    r%   r,   ;TestIOLoopFutures.test_add_future_threads.<locals>.<lambda>  s    499V3Dr(   )
r   r   r3   
add_futurer]  rM   rO   donerP  result)r   poolrf  rj  s   `   r%   test_add_future_threads)TestIOLoopFutures.test_add_future_threads  sz    ''*d LL##E"$D YY[FOOFKKM*fmmo. +**s   BB""
B0c              #   (  #    [         R                  " 5       n[         R                  " 5       nS n[        R                  " 5       R	                  S X1U5      [        R                  " 5       R	                  S X2U5      /v nU R                  X/U5        g 7f)Nc                 F    U R                  5         UR                  5         U $ r*   r   rM   
self_eventother_events     r%   	sync_func=TestIOLoopFutures.test_run_in_executor_gen.<locals>.sync_func  s     NN r(   )r[   r   r	   rM  r6  r   )r   event1event2rx  ress        r%   test_run_in_executor_gen*TestIOLoopFutures.test_run_in_executor_gen  sw     ""	 NN,,T9fMNN,,T9fM
 

 	&)3/s   BBc              #      ^#    [         R                  " 5       n[         R                  " 5       nS mU4S jnU" X5      U" X!5      /v nU R                  X/U5        g 7f)Nc                 F    U R                  5         UR                  5         U $ r*   rt  ru  s     r%   rx  @TestIOLoopFutures.test_run_in_executor_native.<locals>.sync_func  s    NNr(   c                 l   >#    [         R                  " 5       R                  S TX5      I S h  vN $  N7fr*   )r	   rM  r6  )rv  rw  rx  s     r%   async_wrapperDTestIOLoopFutures.test_run_in_executor_native.<locals>.async_wrapper   s1     )99i   s   *424)r[   r   r   )r   rz  r{  r  r|  rx  s        @r%   test_run_in_executor_native-TestIOLoopFutures.test_run_in_executor_native  sT     ""		
 #62M&4QRR&)3/s   AAc              #   p  ^^#    S/m " U4S jS[         R                  5      n[        R                  " 5       mU4S jnU" S5      n[        R
                  " 5       nUR                  U5        UR                  S U5      v   U R                  STS   5        U R                  TR                  5       5        g 7f)Nr   c                   ,   >^  \ rS rSrU U4S jrSrU =r$ )?TestIOLoopFutures.test_set_default_executor.<locals>.MyExecutori-  c                 @   > TS==   S-  ss'   [         TU ]  " U/UQ76 $ )Nr   r   )rY  r]  )r   funcr!   rZ  counts      r%   r]  FTestIOLoopFutures.test_set_default_executor.<locals>.MyExecutor.submit.  s$    aAw~d2T22r(   r+   )r   r   r   r   r]  r   ra  )rZ  r  s   @r%   
MyExecutorr  -  s    3 3r(   r  c                  &   > T R                  5         g r*   )r   )events   r%   rx  >TestIOLoopFutures.test_set_default_executor.<locals>.sync_func4  s    IIKr(   r   )r   r   r[   r   r	   rM  set_default_executorr6  r   rO   is_set)r   r  rx  executorr<   r  r  s        @@r%   test_set_default_executor+TestIOLoopFutures.test_set_default_executor)  s     	333 	3
 !	 a=~~!!(+""433E!H%'s   B2B6r+   N)
r   r   r   r   rp  r   r}  r  r  r   r+   r(   r%   rc  rc    sC    / 0 0* 0 0* ( (r(   rc  c                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)TestIOLoopRunSynci?  c                      [        SS9U l        g )NFr   )r	   r3   rC   s    r%   rD  TestIOLoopRunSync.setUp@  s    51r(   c                 8    U R                   R                  5         g r*   rG  rC   s    r%   rH  TestIOLoopRunSync.tearDownC  s    r(   c                     U R                  [        R                  5         U R                  R	                  S 5        S S S 5        g ! , (       d  f       g = f)Nc                      gN*   r+   r+   r(   r%   r,   4TestIOLoopRunSync.test_sync_result.<locals>.<lambda>H  s    "r(   )rp   r   BadYieldErrorr3   r   rC   s    r%   test_sync_result"TestIOLoopRunSync.test_sync_resultF  s4    s001LL!!*- 211s   A
Ac                     U R                  [        5         U R                  R                  S 5        S S S 5        g ! , (       d  f       g = f)Nc                      SS-  $ r  r+   r+   r(   r%   r,   7TestIOLoopRunSync.test_sync_exception.<locals>.<lambda>L  r  r(   )rp   ZeroDivisionErrorr3   r   rC   s    r%   test_sync_exception%TestIOLoopRunSync.test_sync_exceptionJ  s/    01LL!!-0 211s	   <
A
c                     [         R                  S 5       nU R                  U R                  R	                  U5      S5        g )Nc               3   Z   #    [         R                  v   [         R                  " S5      e7fr  )r   momentReturnr+   r(   r%   r  .TestIOLoopRunSync.test_async_result.<locals>.fO  s     ****R. s   )+r  )r   r  r   r3   r   r   r  s     r%   test_async_result#TestIOLoopRunSync.test_async_resultN  s9    		! 
	! 	..q126r(   c                     [         R                  S 5       nU R                  [        5         U R                  R                  U5        S S S 5        g ! , (       d  f       g = f)Nc               3   :   #    [         R                  v   SS-    g 7fr  r   r  r+   r(   r%   r  1TestIOLoopRunSync.test_async_exception.<locals>.fW  s     **Es   )r   r  rp   r  r3   r   r  s     r%   test_async_exception&TestIOLoopRunSync.test_async_exceptionV  sG    		 
	 01LL!!!$ 211s   A
Ac                 H   ^  U 4S jnT R                   R                  U5        g )Nc                  d   > T R                  [        R                  " 5       T R                  5        g r*   )r   r	   rM  r3   rC   s   r%   r  )TestIOLoopRunSync.test_current.<locals>.f`  s    MM&..*DLL9r(   )r3   r   r  s   ` r%   test_currentTestIOLoopRunSync.test_current_  s    	: 	a r(   c                     [         R                  S 5       nU R                  [        U R                  R
                  USS9  g )Nc               3   <   #    [         R                  " S5      v   g 7fr   )r   rU   r+   r(   r%   r  )TestIOLoopRunSync.test_timeout.<locals>.ff  s     ))A,s   rT   )r   )r   r  rp   r
   r3   r   r  s     r%   test_timeoutTestIOLoopRunSync.test_timeoute  s;    		 
	 	,(=(=q$Or(   c                 t   ^ [         R                  S 5       mU4S jnU R                  R                  U5        g )Nc               3   0   #    [         R                  v   g 7fr*   r  r+   r(   r%   f13TestIOLoopRunSync.test_native_coroutine.<locals>.f1m  s     **s   c                  0   >#    T " 5       I S h  vN   g  N7fr*   r+   )r  s   r%   f23TestIOLoopRunSync.test_native_coroutine.<locals>.f2q  s     $JJs   )r   r  r3   r   )r   r  r  s     @r%   test_native_coroutine'TestIOLoopRunSync.test_native_coroutinel  s2    		 
		 	b!r(   c                     S nU R                  [        5       nU R                  R                  U5        S S S 5        S[	        WR
                  5      ;   d   eg ! , (       d  f       N*= f)Nc                     #    [         R                  " S5      I S h  vN   [        R                  " 5       R	                  5         [         R                  " S5      I S h  vN   g  NF N7f)NrZ   r2   )r;  rU   r	   rM  r9   r+   r(   r%   r  1TestIOLoopRunSync.test_stop_no_timeout.<locals>.fw  sD     --$$$NN!!#--### %#s"   A'A#A A'A%A'%A'zEvent loop stopped)rp   r=  r3   r   str	exception)r   r  cms      r%   test_stop_no_timeout&TestIOLoopRunSync.test_stop_no_timeoutv  sP    	$
 |,LL!!!$ -#s2<<'8888 -,s   A
A')r3   N)r   r   r   r   rD  rH  r  r  r  r  r  r  r  r  r   r+   r(   r%   r  r  ?  s5    2.17%!P"9r(   r  c                   >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)TestPeriodicCallbackMathi  c                     / nSnXAl         U H>  nUR                  U5        UR                  UR                   5        UR                   U-   nM@     U$ )a  Simulate a series of calls to the PeriodicCallback.

Pass a list of call durations in seconds (negative values
work to simulate clock adjustments during the call, or more or
less equivalently, between calls). This method returns the
times at which each call would be made.
r   )_next_timeout_update_nextr   )r   pc	durationsr   r   ds         r%   simulate_calls'TestPeriodicCallbackMath.simulate_calls  sS     AOOC LL))*""Q&C  r(   c                     g r*   r+   rC   s    r%   rf  TestPeriodicCallbackMath.dummy  s    r(   c                     [        U R                  S5      nU R                  U R                  US/S-  5      / SQ5        g )N'  r            i    r   rf  r   r  r   r  s     r%   
test_basic#TestPeriodicCallbackMath.test_basic  s9    djj%0QC!G,.L	
r(   c                     / SQn/ SQn[        U R                  S5      nU R                  U R                  X15      U5        g )N)	   r  r2         r  #   r  r   r   r   )r  r  r  r  i.  iL  ij  i  i  i  i  r  r  )r   call_durationsexpectedr  s       r%   test_overrun%TestPeriodicCallbackMath.test_overrun  s>     A
 djj%0,,R@(Kr(   c                     [        U R                  S5      nU R                  U R                  U/ SQ5      / SQ5        U R                  U R                  U/ SQ5      / SQ5        g )Nr  )r  r   r  )ir   r   )r  r  r  r  r  s     r%   test_clock_backwards-TestPeriodicCallbackMath.test_clock_backwards  sV    djj%0
 	$78:X	
 	,,R>@RSr(   c                   ^ / SQm/ SQnS/[        T5      -  n[        U R                  SSS9nU4S jn[        R                  " SU5         U R                  U R                  X25      U5        S S S 5        g ! , (       d  f       g = f)	N)      ?r   r   g      ?)r  g     @r  g     E@r   r  r  )jitterc                  &   > T R                  S5      $ )Nr   )pop)random_timess   r%   mock_random9TestPeriodicCallbackMath.test_jitter.<locals>.mock_random  s    ##A&&r(   zrandom.random)lenr   rf  r   patchr   r  )r   r  r  r  r  r   s        @r%   test_jitter$TestPeriodicCallbackMath.test_jitter  sl    (0s<00djj%<	' ZZ5T00DhO 655s   "A66
Bc                     [        S [        R                  " SSS95      nSnU R                  UR                  U5        g )Nc                      g r*   r+   r+   r(   r%   r,   9TestPeriodicCallbackMath.test_timedelta.<locals>.<lambda>  s    dr(   r      )minutesr   i8D )r   r7   r8   r   callback_time)r   r  expected_callback_times      r%   test_timedelta'TestPeriodicCallbackMath.test_timedelta  s9    lH,>,>qRT,UV!&))+ABr(   r+   N)r   r   r   r   r  rf  r  r  r  r  r  r   r+   r(   r%   r  r    s)    "
L*T"
PCr(   r  c                   .    \ rS rSrS rSS jrSS jrSrg)TestPeriodicCallbackAsynci  c                    ^ ^ SmSUU 4S jjn[        US5      nUR                  5         T R                  5         UR                  5         T R	                  TS5        g )Nr   c                  >   > T S-  m T S:X  a  TR                  5         g g )Nr   r   ri  )r  r   s   r%   r    ?TestPeriodicCallbackAsync.test_periodic_plain.<locals>.callback  s!    QJEz		 r(   r2   r   returnN)r   r:   rM   r9   r   )r   r    r  r  s   `  @r%   test_periodic_plain-TestPeriodicCallbackAsync.test_periodic_plain  sK    	 	 h+

		
	"r(   Nc                    ^ ^^ SS/m[         R                  SUUU 4S jj5       n[        US5      mTR                  5         T R	                  5         T R                  TS   S5        T R                  TS   S5        g )Nr   c               3      >#    T S==   S-  ss'   [         R                  " S5      v   T S==   S-  ss'   T S   S:X  a6  TR                  5         TR                  R	                  TR                  5        g g 7fNr   r   g?r   r   rU   r9   r3   r&   countsr  r   s   r%   r    >TestPeriodicCallbackAsync.test_periodic_coro.<locals>.callback  s^     1INI))E""1INIayA~	))$))4 s   A3A6r2   r   r   )r  z%Generator[Future[None], object, None])r   r  r   r:   rM   r   r   r    r  r  s   ` @@r%   test_periodic_coro,TestPeriodicCallbackAsync.test_periodic_coro  so    Q		5 	5 
	5 h+

		A&A&r(   c                    ^ ^^ SS/mSUUU 4S jjn[        US5      mTR                  5         T R                  5         T R                  TS   S5        T R                  TS   S5        g )Nr   c                     >#    T S==   S-  ss'   [         R                  " S5      I S h  vN   T S==   S-  ss'   T S   S:X  a6  TR                  5         TR                  R	                  TR                  5        g g  NQ7fr  r  r  s   r%   r    ?TestPeriodicCallbackAsync.test_periodic_async.<locals>.callback  sf     1INI))E"""1INIayA~	))$))4  #s   'A>A<AA>r2   r   r   r  )r   r:   rM   r   r   s   ` @@r%   test_periodic_async-TestPeriodicCallbackAsync.test_periodic_async  s^    Q	5 	5 h+

		A&A&r(   r+   r  )r   r   r   r   r  r!  r&  r   r+   r(   r%   r  r    s    #'$'r(   r  c                   r    \ rS rSrS rS rS r\R                  " \	R                  S:  S5      S 5       rSrg	)
TestIOLoopConfigurationi  c                     SS/[        U5      -   n[        R                  SSR                  U5      /n[	        [
        R                  " U5      5      R                  5       $ )Nz!from tornado.ioloop import IOLoopz*classname = lambda x: x.__class__.__name__z-cz; )listsys
executabler]   r   
subprocesscheck_outputstrip)r   
statements	stmt_listr!   s       r%   
run_python"TestIOLoopConfiguration.run_python	  sX    /8
 	 dii	&:;*11$78>>@@r(   c                     U R                  S5      nU R                  US5        U R                  S5      nU R                  US5        g )N"print(classname(IOLoop.current()))AsyncIOMainLoopzprint(classname(IOLoop()))AsyncIOLoopr3  r   r   clss     r%   test_default$TestIOLoopConfiguration.test_default  sA    ooBC/0oo:;m,r(   c                 L    U R                  SS5      nU R                  US5        g )Nz8IOLoop.configure("tornado.platform.asyncio.AsyncIOLoop")r6  r7  r9  r:  s     r%   test_asyncio$TestIOLoopConfiguration.test_asyncio  s)    ooF0
 	/0r(   )r      z*implicit event loop creation not availablec                 N    U R                  SSS5      nU R                  US5        g )Nz4from tornado.platform.asyncio import AsyncIOMainLoopzAsyncIOMainLoop().install()r6  r7  r9  r:  s     r%   test_asyncio_main)TestIOLoopConfiguration.test_asyncio_main  s.     ooB)0

 	/0r(   r+   N)r   r   r   r   r3  r<  r?  unittestskipIfr,  version_inforC  r   r+   r(   r%   r)  r)    s@    A-1 __G#%Q11r(   r)  __main__)5r;  concurrent.futuresr   
concurrentr   collections.abcr   r   r7   r   r   r.  r,  r[   rG   r4   rE  r   tornado.escaper   tornador   tornado.ioloopr	   r
   r   tornado.logr   tornado.testingr   r   r   r   r   tornado.test.utilr   r   tornado.concurrentr   typingTYPE_CHECKINGr   r   TestCaserA  rW  rc  r  r  r  r)  r   mainr+   r(   r%   <module>rW     s    1  %      
      %  A A   & 	R Rn6)) 6D1] 1M( M(`?9)) ?9DPCx00 PCf1' 1'h 1h//  1F zMMO r(   