
    Xh:m                     V   d dl Z d dlmZ d dlmZ d dlmZ d dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZmZmZm Z m!Z! d dl"m#Z#m$Z$ d dl%m&Z& d dl'Z'e'jP                  rd dl'm)Z)  G d de      Z* G d dejV                        Z, G d de      Z- G d de      Z. G d dejV                        Z/ G d dejV                        Z0 G d de      Z1 G d dejV                        Z2e3dk(  r ejh                          yy)    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                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zed
        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed        Zeed               Zd Z y)
TestIOLoopc                    d| _         | j                  }| |j                  fd}t        j                  ||      |_        |j                  d        |j                  d        |j                  t        j                  d      |j                         |j                          | j                  | j                   d       y )Nr   c                 H    xj                   dz  c_          |g|i | y N   calls)selfcallbackargskwargsold_add_callbacktests       L/var/www/html/myenv/lib/python3.12/site-packages/tornado/test/ioloop_test.pyadd_callbackzBTestIOLoop.test_add_callback_return_sequence.<locals>.add_callback1   s"    JJ!OJX777    c                      i S N r)   r&   r$   <lambda>z>TestIOLoop.test_add_callback_return_sequence.<locals>.<lambda>6       " r&   c                      g S r(   r)   r)   r&   r$   r*   z>TestIOLoop.test_add_callback_return_sequence.<locals>.<lambda>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_sequencez,TestIOLoop.test_add_callback_return_sequence)   s    
||,,	8 ",,\4@*%*%++<diiH



B'r&   c                 <     fd fd} j                   j                   j                   j                         |        j                           j	                  t        j                          j
                  d        j                   j                         y )Nc                  4    d _          j                          y NT)calledr6   r   s   r$   r   z5TestIOLoop.test_add_callback_wakeup.<locals>.callback?   s    DKIIKr&   c                  |    d_         j                  j                          t        j                         _        y NF)r>   r0   r%   time
start_time)r   r   s   r$   schedule_callbackz>TestIOLoop.test_add_callback_wakeup.<locals>.schedule_callbackC   s)    DKLL%%h/"iikDOr&      )places)r0   r3   rB   waitassertAlmostEqualrC   
assertTruer>   )r   rD   r   s   ` @r$   test_add_callback_wakeupz#TestIOLoop.test_add_callback_wakeup<   si    		* 	  !2!2!46GH		tyy{DOOAF$r&   c                 ,     fd}t        j                  |      } j                  j                  |j                          j                          t        j                          j                  z
  } j                  |d       |j                          y )Nc                      t        j                  d       t        j                           _         j                  j	                   j
                         y )N{Gz?)rB   sleep	stop_timer0   r%   r6   r?   s   r$   targetz@TestIOLoop.test_add_callback_wakeup_other_thread.<locals>.targetO   s2    JJt!YY[DNLL%%dii0r&   rP   皙?)
	threadingThreadr0   r%   r7   rG   rB   rO   r8   join)r   rP   threaddeltas   `   r$   %test_add_callback_wakeup_other_threadz0TestIOLoop.test_add_callback_wakeup_other_threadN   sd    	1 !!0!!&,,/				dnn,s#r&   c                     | j                   j                  t        j                  d      | j                         | j                          y )Nr   )microseconds)r0   r3   r4   r5   r6   rG   r?   s    r$   test_add_timeout_timedeltaz%TestIOLoop.test_add_timeout_timedelta\   s.      !3!3!CTYYO		r&   c                    t               \  }}	 | j                  j                  |j                         d t        j
                         | j                  t        | j                  j                  |j                         d t        j
                         | j                  j                  |j                                |j                          y # | j                  j                  |j                                |j                          w xY w)Nc                      y r(   r)   fdeventss     r$   r*   z.TestIOLoop.test_multiple_add.<locals>.<lambda>d       r&   c                      y r(   r)   r^   s     r$   r*   z.TestIOLoop.test_multiple_add.<locals>.<lambda>l   ra   r&   )
r   r0   add_handlerfilenor	   READassertRaises	Exceptionremove_handlercloser   sockports      r$   test_multiple_addzTestIOLoop.test_multiple_add`   s    %'
d	LL$$6
 ((' LL''6JJL LL''6JJLs   BC ;Dc                     t               \  }}	 | j                  j                  |j                                |j	                          y # |j	                          w xY wr(   )r   r0   rh   rd   ri   rj   s      r$   test_remove_without_addz"TestIOLoop.test_remove_without_adds   s@     &'
d	LL''6JJLDJJLs   )A	 	Ac                     t               5  | j                  j                  | j                         d d d        | j	                          y # 1 sw Y   xY wr(   )r   r0   add_callback_from_signalr6   rG   r?   s    r$   test_add_callback_from_signalz(TestIOLoop.test_add_callback_from_signal|   s>      ! 	=LL11$))<	=			= 	=s   &A

Ac                 0   t        d      }t        j                  |j                        }|j                          t	               5  |j                  |j                         d d d        |j                          |j                          y # 1 sw Y   *xY w)NFmake_currentrQ   )	r	   rS   rT   r7   r   rq   r6   rU   ri   )r   other_iolooprV   s      r$   *test_add_callback_from_signal_other_threadz5TestIOLoop.test_add_callback_from_signal_other_thread   su     51!!););<! 	E11,2C2CD	E	E 	Es   BBc                    t        j                         fd}t        d      t        j                  |      }|j	                          j                          t        d      D ]  }j                  d         y )Nc                      j                  j                         j                           j                          j	                  d       y )NTall_fds)r%   r6   r7   setri   )closingrv   s   r$   rP   z:TestIOLoop.test_add_callback_while_closing.<locals>.target   s=    %%l&7&78 KKMt,r&   Frt   rQ     c                       y r(   r)   r)   r&   r$   r*   z<TestIOLoop.test_add_callback_while_closing.<locals>.<lambda>   ra   r&   )rS   Eventr	   rT   r7   rG   ranger%   )r   rP   rV   ir}   rv   s       @@r$   test_add_callback_while_closingz*TestIOLoop.test_add_callback_while_closing   se     //#	- 51!!0t 	4A%%l3	4r&   c                 X    t        j                         \  }}	  fd} j                  j                  |j	                         |t
        j                          j                  j                   j                  j                         dz   t        j                  |j                  d              j                           j                  j                  |j	                                |j                          |j                          y # |j                          |j                          w xY w)Nc                 f    j                  |t        j                         j                          y r(   )assertEqualr	   re   r6   )r_   r`   r   s     r$   handlerz5TestIOLoop.test_read_while_writeable.<locals>.handler   s       5		r&   rM   s   asdf)socket
socketpairr0   rc   rd   r	   re   r3   rB   	functoolspartialsendrG   rh   ri   )r   clientserverr   s   `   r$   test_read_while_writeablez$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                     | j                   j                  | j                   j                         | j                        }| j	                          | j                   j                  |       y r(   )r0   r3   rB   r6   rG   remove_timeoutr   handles     r$   test_remove_timeout_after_firez)TestIOLoop.test_remove_timeout_after_fire   sD    ))$,,*;*;*=tyyI		##F+r&   c                 (    t        d      D ]U  } j                  j                   j                  j                         dz   d       } j                  j	                  |       W  j                  j                   fd        j                          y )Ni  i  c                       y r(   r)   r)   r&   r$   r*   z8TestIOLoop.test_remove_timeout_cleanup.<locals>.<lambda>   ra   r&   c                  N     j                   j                   j                        S r(   r0   r%   r6   r?   s   r$   r*   z8TestIOLoop.test_remove_timeout_cleanup.<locals>.<lambda>   s    $,,*C*CDII*N r&   )r   r0   r3   rB   r   r%   rG   )r   r   timeouts   `  r$   test_remove_timeout_cleanupz&TestIOLoop.test_remove_timeout_cleanup   sp     t 	1All..t||/@/@/BT/I<XGLL''0	1 	!!"NO		r&   c                     ddg j                   j                         } fd} j                   j                  |dz   |       fd} j                   j                  |dz   |       j                   j                  |dz    j                         t        j                  d        j                           j                  ddg       y )NFc                  F    d d<   j                   j                         y NTr   )r0   r   )r   r   	t2_handles   r$   t1z7TestIOLoop.test_remove_timeout_from_timeout.<locals>.t1   s    E!HLL''	2r&   rM   c                      d d<   y )NTr   r)   r   s   r$   t2z7TestIOLoop.test_remove_timeout_from_timeout.<locals>.t2   s    E!Hr&   g{Gz?gQ?T)r0   rB   r3   r6   rN   rG   r   )r   nowr   r   r   r   s   `   @@r$    test_remove_timeout_from_timeoutz+TestIOLoop.test_remove_timeout_from_timeout   s    
 ll!	3 	  tR0	 LL,,S4Z<	  tTYY7

4		u.r&   c                 n   g }| j                   j                  | j                   j                         |j                  d       | j                   j                  t	        j
                  d      |j                  d       | j                   j                  | j                   j                         |j                  d       | j                   j                  d|j                  d       | j                   j                  d| j                         | j                          | j                  t        |      g d       y )Nr   r   )secondsrE         )r   rE   r   r   )r0   r3   rB   appendr4   r5   call_at
call_laterr6   rG   r   sorted)r   resultss     r$   test_timeout_with_argumentsz&TestIOLoop.test_timeout_with_arguments   s      !2!2!4gnnaH  !3!3A!>PQRT\\..0'..!D7>>15499-		 	,7r&   c                     | j                   j                  | j                   j                         d       }| j                  |       | j                   j	                  |       y )Nc                       y r(   r)   r)   r&   r$   r*   z4TestIOLoop.test_add_timeout_return.<locals>.<lambda>   ra   r&   )r0   r3   rB   assertIsNotNoner   r   s     r$   test_add_timeout_returnz"TestIOLoop.test_add_timeout_return   sG     ))$,,*;*;*=|LV$##F+r&   c                     | j                   j                  | j                   j                         d       }| j                  |       | j                   j	                  |       y )Nc                       y r(   r)   r)   r&   r$   r*   z0TestIOLoop.test_call_at_return.<locals>.<lambda>   ra   r&   )r0   r   rB   r   r   r   s     r$   test_call_at_returnzTestIOLoop.test_call_at_return   sE    %%dll&7&7&9<HV$##F+r&   c                     | j                   j                  dd       }| j                  |       | j                   j                  |       y )Nr   c                       y r(   r)   r)   r&   r$   r*   z3TestIOLoop.test_call_later_return.<locals>.<lambda>   ra   r&   )r0   r   r   r   r   s     r$   test_call_later_returnz!TestIOLoop.test_call_later_return   s8    ((L9V$##F+r&   c                      G d d      }t               \  }} ||      t        d      j                  fd       j                  d       | j	                  j
                         y)	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                       e Zd Zd Zd Zd Zy)8TestIOLoop.test_close_file_object.<locals>.SocketWrapperc                      || _         d| _        y rA   )sockobjclosed)r   r   s     r$   __init__zATestIOLoop.test_close_file_object.<locals>.SocketWrapper.__init__
  s    &#r&   c                 6    | j                   j                         S r(   )r   rd   r?   s    r$   rd   z?TestIOLoop.test_close_file_object.<locals>.SocketWrapper.fileno  s    ||**,,r&   c                 F    d| _         | j                  j                          y r=   )r   r   ri   r?   s    r$   ri   z>TestIOLoop.test_close_file_object.<locals>.SocketWrapper.close  s    """$r&   N)__name__
__module____qualname__r   rd   ri   r)   r&   r$   SocketWrapperr   	  s    $-%r&   r   Frt   c                  H     j                  d t        j                        S )Nc                      y r(   r)   r^   s     r$   r*   zETestIOLoop.test_close_file_object.<locals>.<lambda>.<locals>.<lambda>  ra   r&   )rc   r	   re   )r0   socket_wrappers   r$   r*   z3TestIOLoop.test_close_file_object.<locals>.<lambda>  s    G'' 7 r&   Trz   N)r   r	   run_syncri   rI   r   )r   r   r   rl   r0   r   s       @@r$   test_close_file_objectz!TestIOLoop.test_close_file_object   sd    
	% 
	% )*&w/e,	

 	d#--.r&   c                     t               \  }g  fd} j                  j                  |t        j                         t        j                  t        j                               5 }|j                  d|f        j                          ddd        j                  j                          j                  j                  j                         |t        j                         t        j                  t        j                               5 }|j                  d|f        j                          ddd        j                  d           j                  d   j                                 j                  j                  j                                j                          y# 1 sw Y   #xY w# 1 sw Y   xY w)z>The handler callback receives the same fd object it passed in.c                     j                  |        j                         \  }}|j                          j                          y r(   )r   acceptri   r6   )r_   r`   connaddrfdsr   server_socks       r$   handle_connectionzGTestIOLoop.test_handler_callback_file_object.<locals>.handle_connection%  s2    JJrN$++-JD$JJLIIKr&   z	127.0.0.1Nr   r   )r   r0   rc   r	   re   
contextlibr}   r   connectrG   rh   rd   assertIsr   ri   )r   rl   r   client_sockr   r   s   `   @@r$   !test_handler_callback_file_objectz,TestIOLoop.test_handler_callback_file_object   sU   ,.T	 	  .?M0 	Kd 34IIK	 	##K0  !3!3!57H&++V0 	Kd 34IIK	 	c!fk*Q!3!3!56##K$6$6$89	 	
	 	s   ,$F1$F>1F;>Gc                    t               \  }}d }| j                  j                  ||t        j                         | j                  t              5  | j                  j                  |j                         |t        j                         d d d        | j                  j                  |j                                |j                          y # 1 sw Y   CxY w)Nc                      y r(   r)   r^   s     r$   fz+TestIOLoop.test_mixed_fd_fileobj.<locals>.f<  s    r&   )
r   r0   rc   r	   re   rf   rg   rd   rh   ri   )r   r   rl   r   s       r$   test_mixed_fd_fileobjz TestIOLoop.test_mixed_fd_fileobj9  s    ,.T	 	  a=y) 	K LL$$[%7%7%91fkkJ	K 	##K$6$6$89	K 	Ks   :CCc                      dgdg fd} j                   j                  |        j                           j                  d           j	                  d          y)z:Calling start() twice should raise an error, not deadlock.Fc                      	 j                   j                          dd<   j                          y # t        $ r d d<   Y !w xY wr   )r0   r7   rg   r6   )got_exceptionreturned_from_startr   s   r$   r   z+TestIOLoop.test_reentrant.<locals>.callbackL  sI    (""$)-#A& IIK  (#'a (s   3 AAr   N)r0   r%   rG   rI   assertFalse)r   r   r   r   s   ` @@r$   test_reentrantzTestIOLoop.test_reentrantG  sY    $g	 	!!(+		a(),Q/0r&   c                     | j                   j                  d        | j                   j                  | j                         t        t        d      5  | j                          ddd       y# 1 sw Y   yxY w)z-Uncaught exceptions get logged by the IOLoop.c                      ddz  S Nr   r   r)   r)   r&   r$   r*   z3TestIOLoop.test_exception_logging.<locals>.<lambda>[  
    !a% r&   Exception in callbackN)r0   r%   r6   r   r   rG   r?   s    r$   test_exception_loggingz!TestIOLoop.test_exception_loggingY  sS    !!-0!!$)),w 78 	IIK	 	 	s   A,,A5c                      t         j                   fd       } j                  j                  |       t	        t
        d      5   j                          ddd       y# 1 sw Y   yxY w)z:The IOLoop examines exceptions from Futures and logs them.c                  Z     j                   j                   j                         ddz   y r   r   r?   s   r$   r   z:TestIOLoop.test_exception_logging_future.<locals>.callbackc  s     LL%%dii0Er&   r   N)r   	coroutiner0   r%   r   r   rG   r   r   s   ` r$   test_exception_logging_futurez(TestIOLoop.test_exception_logging_future`  sX     
	 
	 	!!(+w 78 	IIK	 	 	s   AA(c                       fd} j                   j                  |       t        t        d      5   j	                          ddd       y# 1 sw Y   yxY w)z=The IOLoop examines exceptions from awaitables and logs them.c                     K    j                   j                   j                   j                   j                         ddz   y wr   r   r?   s   r$   r   z?TestIOLoop.test_exception_logging_native_coro.<locals>.callbacko  s2      LL%%dll&?&?KEs   AAr   N)r0   r%   r   r   rG   r   s   ` r$   "test_exception_logging_native_coroz-TestIOLoop.test_exception_logging_native_corol  sE    	 	!!(+w 78 	IIK	 	 	s   AAc                    | j                   j                  d        | j                   j                  | j                         t        t        d      5  | j                          d d d        | j                   j                  d        | j                   j                  | j                         t        t        d      5  | j                          d d d        y # 1 sw Y   txY w# 1 sw Y   y xY w)Nc                      ddz  S r   r)   r)   r&   r$   r*   z0TestIOLoop.test_spawn_callback.<locals>.<lambda>|  r   r&   r   c                      ddz  S r   r)   r)   r&   r$   r*   z0TestIOLoop.test_spawn_callback.<locals>.<lambda>  s
    AE r&   )r0   r%   r6   r   r   rG   spawn_callbackr?   s    r$   test_spawn_callbackzTestIOLoop.test_spawn_callbacky  s     	!!-0!!$)),w 78 	IIK	 	##M2!!$)),w 78 	IIK	 		 		 	s   C<C"C"C+c                 t    t        j                         \  	 j                  d       j                  d       g  fd} j                  j	                  | j                  j
                          j                  j	                  | j                  j
                          j                  j                  d j                          j                           j                  dg       j                          j                          y # j                          j                          w xY w)Ns   abcc                     j                  | j                  d             | u rj                  j                         y j                  j                         y )Ni   )r   recvr0   rh   )r_   r`   chunksr   r   r   s     r$   handle_readz@TestIOLoop.test_remove_handler_from_handler.<locals>.handle_read  sB    bggdm,<LL//7LL//7r&   rR   )r   r   r   r0   rc   re   r   r6   rG   r   ri   )r   r   r   r   r   s   ` @@@r$    test_remove_handler_from_handlerz+TestIOLoop.test_remove_handler_from_handler  s      **,	KKKK F8 LL$$V[$,,:K:KLLL$$V[$,,:K:KLLL##C3IIK VfX.LLNLLN LLNLLNs   CD "D7c           	   #      K   d }t        j                  t        d      D cg c]  }| j                  j	                  d |        c}       y c c}w w)Nc                  \    t        d      D ]  } t        d      }|j                            y )Nr/   Frt   )r   r	   ri   )r   r9   s     r$   r   z*TestIOLoop.test_init_close_race.<locals>.f  s(    2Y 51

r&   rE   )r   multir   r0   run_in_executor)r   r   r   s      r$   test_init_close_racezTestIOLoop.test_init_close_race  s?     	
 iiaQ155dA>QRRQs    A#AAc                     t        j                         }t        |d      }|j                  |u sJ | j	                  t
              5  t        |d       d d d        |j                          y # 1 sw Y   xY w)NF)asyncio_loopru   )asyncionew_event_loopr	   r   rf   RuntimeErrorri   )r   r   r9   s      r$   test_explicit_asyncio_loopz%TestIOLoop.test_explicit_asyncio_loop  sl    --/<eD  L000|, 	B5A	B 	

	B 	Bs   A..A7N)!r   r   r   r:   rJ   rX   r[   rm   ro   rr   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r)   r&   r$   r   r   (   s    (&%$&
4&  *,/.8,,
,
/@21$
  8 S  Sr&   r   c                   $    e Zd Zd Zd Zd Zd Zy)TestIOLoopCurrentc                 b    t        | t                      d | _        t        j                          y r(   )r   r   r0   r	   clear_currentr?   s    r$   setUpzTestIOLoopCurrent.setUp  s#    "4);)=>r&   c                 R    | j                   | j                   j                          y y r(   r0   ri   r?   s    r$   tearDownzTestIOLoopCurrent.tearDown  s!    <<#LL  $r&   c                     t        d       _         j                  t        j                  d             t	        d      D ]  } fd} j                  j                  |        j                  j                           j                   j                   j                          j                  t        j                  d              y )NFrt   )instancer   c                      t        j                          _         j                  J  j                  j	                          y r(   )r	   currentcurrent_io_loopr0   r6   r?   s   r$   r   z-TestIOLoopCurrent.test_non_current.<locals>.f  s2    '-~~'7$||///!!#r&   )	r	   r0   assertIsNoner  r   r%   r7   r   r  )r   r   r   s   `  r$   test_non_currentz"TestIOLoopCurrent.test_non_current  s    51&..%89 q 	>A$
 LL%%a(LL MM$..=fnne<=	>r&   c                     t        d      | _        | j                  | j                  t        j                                y )NTrt   )r	   r0   r   r  r?   s    r$   test_force_currentz$TestIOLoopCurrent.test_force_current  s'    40dllFNN$45r&   N)r   r   r   r	  r  r  r  r)   r&   r$   r  r    s    
!>&6r&   r  c                   .     e Zd Z fdZed        Z xZS )TestIOLoopCurrentAsyncc                 J    t         |           t        | t                      y r(   )superr	  r   r   )r   	__class__s    r$   r	  zTestIOLoopCurrentAsync.setUp  s    "4);)=>r&   c              #      K   t        d      5 }|j                  t        j                         d d d        y # 1 sw Y   y xY wwr   )r   submitr	   r  )r   es     r$   test_clear_without_currentz1TestIOLoopCurrentAsync.test_clear_without_current  s;     
  " 	1a((6//00	1 	1 	1s   A"9	AAA)r   r   r   r	  r   r  __classcell__)r  s   @r$   r  r    s    ? 1 1r&   r  c                   B    e Zd Zd Zed        Zed        Zed        Zy)TestIOLoopFuturesc                 X    t        j                  d      5 }d } j                  j                  |j	                  |       fd        j                         } j                  |j                                 j                  |j                                d d d        y # 1 sw Y   y xY w)Nr   c                       y r(   r)   r)   r&   r$   dummyz8TestIOLoopFutures.test_add_future_threads.<locals>.dummy  s    r&   c                 &    j                  |       S r(   r6   )futurer   s    r$   r*   z;TestIOLoopFutures.test_add_future_threads.<locals>.<lambda>  s    499V3D r&   )
r   r   r0   
add_futurer  rG   rI   doner  result)r   poolr$  r'  s   `   r$   test_add_future_threadsz)TestIOLoopFutures.test_add_future_threads  s    ''* 
	/d LL##E"$D YY[FOOFKKM*fmmo.
	/ 
	/ 
	/s   B B  B)c              #   &  K   t        j                         }t        j                         }d }t        j                         j	                  d |||      t        j                         j	                  d |||      g}| j                  ||g|       y w)Nc                 F    | j                          |j                          | S r(   r|   rG   
self_eventother_events     r$   	sync_funcz=TestIOLoopFutures.test_run_in_executor_gen.<locals>.sync_func  s     NN r&   )rS   r   r	   r  r   r   )r   event1event2r3  ress        r$   test_run_in_executor_genz*TestIOLoopFutures.test_run_in_executor_gen  s~     ""	 NN,,T9ffMNN,,T9ffM
 

 	&&)3/s   BBc              #      K   t        j                         }t        j                         }d fd} |||       |||      g}| j                  ||g|       y w)Nc                 F    | j                          |j                          | S r(   r/  r0  s     r$   r3  z@TestIOLoopFutures.test_run_in_executor_native.<locals>.sync_func  s    NNr&   c                 l   K   t        j                         j                  d | |       d {   S 7 wr(   )r	   r  r   )r1  r2  r3  s     r$   async_wrapperzDTestIOLoopFutures.test_run_in_executor_native.<locals>.async_wrapper   s4     )99i[   s   *424)rS   r   r   )r   r4  r5  r;  r6  r3  s        @r$   test_run_in_executor_nativez-TestIOLoopFutures.test_run_in_executor_native  s[     ""		
 #662M&&4QRR&&)3/s   AAc              #   h  K   dg G fddt         j                        }t        j                         fd} |d      }t	        j
                         }|j                  |       |j                  d |       | j                  dd          | j                  j                                y w)Nr   c                   "     e Zd Z fdZ xZS )?TestIOLoopFutures.test_set_default_executor.<locals>.MyExecutorc                 >    dxx   dz  cc<   t        |   |g| S )Nr   r   )r  r  )r   funcr    r  counts      r$   r  zFTestIOLoopFutures.test_set_default_executor.<locals>.MyExecutor.submit.  s$    aAw~d2T22r&   )r   r   r   r  r  )r  rB  s   @r$   
MyExecutorr?  -  s    3 3r&   rC  c                  &     j                          y r(   )r|   )events   r$   r3  z>TestIOLoopFutures.test_set_default_executor.<locals>.sync_func4  s    IIKr&   r   )r   r   rS   r   r	   r  set_default_executorr   r   rI   is_set)r   rC  r3  executorr9   rB  rE  s        @@r$   test_set_default_executorz+TestIOLoopFutures.test_set_default_executor)  s     	333 	3
 !	 a=~~!!(+""433E!H%'s   B.B2N)r   r   r   r,  r   r7  r<  rI  r)   r&   r$   r!  r!    sC    / 0 0* 0 0* ( (r&   r!  c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestIOLoopRunSyncc                 &    t        d      | _        y )NFrt   )r	   r0   r?   s    r$   r	  zTestIOLoopRunSync.setUp@  s    51r&   c                 8    | j                   j                          y r(   r  r?   s    r$   r  zTestIOLoopRunSync.tearDownC  s    r&   c                     | j                  t        j                        5  | j                  j	                  d        d d d        y # 1 sw Y   y xY w)Nc                       yN*   r)   r)   r&   r$   r*   z4TestIOLoopRunSync.test_sync_result.<locals>.<lambda>H  ra   r&   )rf   r   BadYieldErrorr0   r   r?   s    r$   test_sync_resultz"TestIOLoopRunSync.test_sync_resultF  s=    s001 	.LL!!*-	. 	. 	.s   AAc                     | j                  t              5  | j                  j                  d        d d d        y # 1 sw Y   y xY w)Nc                      ddz  S r   r)   r)   r&   r$   r*   z7TestIOLoopRunSync.test_sync_exception.<locals>.<lambda>L  r   r&   )rf   ZeroDivisionErrorr0   r   r?   s    r$   test_sync_exceptionz%TestIOLoopRunSync.test_sync_exceptionJ  s8    01 	1LL!!-0	1 	1 	1s	   <Ac                     t         j                  d        }| j                  | j                  j	                  |      d       y )Nc               3   X   K   t         j                   t        j                  d      wrP  )r   momentReturnr)   r&   r$   r   z.TestIOLoopRunSync.test_async_result.<locals>.fO  s     ****R. s   (*rQ  )r   r   r   r0   r   r   r   s     r$   test_async_resultz#TestIOLoopRunSync.test_async_resultN  s9    		! 
	! 	..q126r&   c                     t         j                  d        }| j                  t              5  | j                  j                  |       d d d        y # 1 sw Y   y xY w)Nc               3   :   K   t         j                   ddz   y wr   r   rZ  r)   r&   r$   r   z1TestIOLoopRunSync.test_async_exception.<locals>.fW  s     **E   )r   r   rf   rV  r0   r   r\  s     r$   test_async_exceptionz&TestIOLoopRunSync.test_async_exceptionV  sP    		 
	 01 	%LL!!!$	% 	% 	%s   AAc                 F      fd} j                   j                  |       y )Nc                  b     j                  t        j                          j                         y r(   )r   r	   r  r0   r?   s   r$   r   z)TestIOLoopRunSync.test_current.<locals>.f`  s    MM&..*DLL9r&   )r0   r   r\  s   ` r$   test_currentzTestIOLoopRunSync.test_current_  s    	: 	a r&   c                     t         j                  d        }| j                  t        | j                  j
                  |d       y )Nc               3   :   K   t        j                  d       y wr   )r   rN   r)   r&   r$   r   z)TestIOLoopRunSync.test_timeout.<locals>.ff  s     ))A,ra  rM   )r   )r   r   rf   r
   r0   r   r\  s     r$   test_timeoutzTestIOLoopRunSync.test_timeoute  s;    		 
	 	,(=(=q$Or&   c                 r    t         j                  d        fd}| j                  j                  |       y )Nc               3   0   K   t         j                   y wr(   r`  r)   r&   r$   f1z3TestIOLoopRunSync.test_native_coroutine.<locals>.f1m  s     **s   c                  0   K             d {    y 7 wr(   r)   )rk  s   r$   f2z3TestIOLoopRunSync.test_native_coroutine.<locals>.f2q  s     $JJs   )r   r   r0   r   )r   rm  rk  s     @r$   test_native_coroutinez'TestIOLoopRunSync.test_native_coroutinel  s2    		 
		 	b!r&   c                     d }| j                  t              5 }| j                  j                  |       d d d        dt	        j
                        v sJ y # 1 sw Y   #xY w)Nc                     K   t        j                  d       d {    t        j                         j	                          t        j                  d       d {    y 7 D7 w)NrR   r/   )r  rN   r	   r  r6   r)   r&   r$   r   z1TestIOLoopRunSync.test_stop_no_timeout.<locals>.fw  sF     --$$$NN!!#--### %#s!   A$A >A$A"A$"A$zEvent loop stopped)rf   r  r0   r   str	exception)r   r   cms      r$   test_stop_no_timeoutz&TestIOLoopRunSync.test_stop_no_timeoutv  sW    	$
 |, 	%LL!!!$	%#s2<<'8888	% 	%s   AA N)r   r   r   r	  r  rS  rW  r]  rb  re  rh  rn  rt  r)   r&   r$   rK  rK  ?  s5    2.17%!P"9r&   rK  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestPeriodicCallbackMathc                     g }d}||_         |D ]=  }|j                  |       |j                  |j                          |j                   |z   }? |S )a9  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_callsz'TestPeriodicCallbackMath.simulate_calls  sZ      	'AOOC LL))*""Q&C	' r&   c                      y r(   r)   r?   s    r$   r$  zTestPeriodicCallbackMath.dummy  s    r&   c                     t        | j                  d      }| j                  | j                  |dgdz        g d       y )N'  r            i    r   r$  r   r}  r   rz  s     r$   
test_basicz#TestPeriodicCallbackMath.test_basic  s9    djj%0QC!G,.L	
r&   c                     g d}g d}t        | j                  d      }| j                  | j                  ||      |       y )N)	   r  r/         r  #   r  r   r   r   )r  r  r  r  i.  iL  ij  i  i  i  i  r  r  )r   call_durationsexpectedrz  s       r$   test_overrunz%TestPeriodicCallbackMath.test_overrun  s@     A
 djj%0,,R@(Kr&   c                     t        | j                  d      }| j                  | j                  |g d      g d       | j                  | j                  |g d      g d       y )Nr  )r  r   r  )ir   r   )r  r  r  r  r  s     r$   test_clock_backwardsz-TestPeriodicCallbackMath.test_clock_backwards  sV    djj%0
 	$78:X	
 	,,R>@RSr&   c                    g dg d}dgt              z  }t        | j                  dd      }fd}t        j                  d|      5  | j                  | j                  ||      |       d d d        y # 1 sw Y   y xY w)	N)      ?r   r   g      ?)r  g     @r  g     E@r   r  r  )jitterc                  &     j                  d      S )Nr   )pop)random_timess   r$   mock_randomz9TestPeriodicCallbackMath.test_jitter.<locals>.mock_random  s    ##A&&r&   zrandom.random)lenr   r$  r   patchr   r}  )r   r  r  rz  r  r  s        @r$   test_jitterz$TestPeriodicCallbackMath.test_jitter  s{    (0s<00djj%<	' ZZ5 	PT00^DhO	P 	P 	Ps   #A88Bc                     t        d t        j                  dd            }d}| j                  |j                  |       y )Nc                       y r(   r)   r)   r&   r$   r*   z9TestPeriodicCallbackMath.test_timedelta.<locals>.<lambda>  ra   r&   r      )minutesr   i8D )r   r4   r5   r   callback_time)r   rz  expected_callback_times      r$   test_timedeltaz'TestPeriodicCallbackMath.test_timedelta  s9    lH,>,>qRT,UV!&))+ABr&   N)
r   r   r   r}  r$  r  r  r  r  r  r)   r&   r$   rv  rv    s)    "
L*T"
PCr&   rv  c                   "    e Zd Zd ZddZddZy)TestPeriodicCallbackAsyncc                      dd fd}t        |d      }|j                           j                          |j                           j	                  d       y )Nr   c                  <     dz    dk(  rj                          y y )Nr   r   r&  )rB  r   s   r$   r   z?TestPeriodicCallbackAsync.test_periodic_plain.<locals>.callback  s!    QJEz		 r&   r/   r   returnN)r   r7   rG   r6   r   )r   r   rz  rB  s   `  @r$   test_periodic_plainz-TestPeriodicCallbackAsync.test_periodic_plain  sF    	 h+

		
	"r&   Nc                      ddgt         j                  d fd       }t        |d      j                           j	                           j                  d   d        j                  d   d       y )Nr   c               3      K    dxx   dz  cc<   t        j                  d        dxx   dz  cc<    d   dk(  r6j                          j                  j	                  j                         y y wNr   r   g?r   r   rN   r6   r0   r%   countsrz  r   s   r$   r   z>TestPeriodicCallbackAsync.test_periodic_coro.<locals>.callback  s_     1INI))E""1INIayA~	))$))4 s   A1A4r/   r   r   )r  z%Generator[Future[None], object, None])r   r   r   r7   rG   r   r   r   r  rz  s   ` @@r$   test_periodic_coroz,TestPeriodicCallbackAsync.test_periodic_coro  sj    Q		5 
	5 h+

		A&A&r&   c                      ddgd fd}t        |d      j                           j                           j                  d   d        j                  d   d       y )Nr   c                     K    dxx   dz  cc<   t        j                  d       d {     dxx   dz  cc<    d   dk(  r6j                          j                  j	                  j                         y y 7 Pwr  r  r  s   r$   r   z?TestPeriodicCallbackAsync.test_periodic_async.<locals>.callback  sg     1INI))E"""1INIayA~	))$))4  #s   &A<A:AA<r/   r   r   r  )r   r7   rG   r   r  s   ` @@r$   test_periodic_asyncz-TestPeriodicCallbackAsync.test_periodic_async  sY    Q	5 h+

		A&A&r&   r  )r   r   r   r  r  r  r)   r&   r$   r  r    s    #'$'r&   r  c                   j    e Zd Zd Zd Zd Z ej                  ej                  dk\  d      d        Z
y)TestIOLoopConfigurationc                     ddgt        |      z   }t        j                  ddj                  |      g}t	        t        j                  |            j                         S )Nz!from tornado.ioloop import IOLoopz*classname = lambda x: x.__class__.__name__z-cz; )listsys
executablerU   r   
subprocesscheck_outputstrip)r   
statements	stmt_listr    s       r$   
run_pythonz"TestIOLoopConfiguration.run_python	  sX    /8
 	 dii	&:;*11$78>>@@r&   c                     | j                  d      }| j                  |d       | j                  d      }| j                  |d       y )N"print(classname(IOLoop.current()))AsyncIOMainLoopzprint(classname(IOLoop()))AsyncIOLoopr  r   r   clss     r$   test_defaultz$TestIOLoopConfiguration.test_default  sA    ooBC/0oo:;m,r&   c                 L    | j                  dd      }| j                  |d       y )Nz8IOLoop.configure("tornado.platform.asyncio.AsyncIOLoop")r  r  r  r  s     r$   test_asyncioz$TestIOLoopConfiguration.test_asyncio  s)    ooF0
 	/0r&   )r      z*implicit event loop creation not availablec                 N    | j                  ddd      }| j                  |d       y )Nz4from tornado.platform.asyncio import AsyncIOMainLoopzAsyncIOMainLoop().install()r  r  r  r  s     r$   test_asyncio_mainz)TestIOLoopConfiguration.test_asyncio_main  s.     ooB)0

 	/0r&   N)r   r   r   r  r  r  unittestskipIfr  version_infor  r)   r&   r$   r  r    sB    A-1 X__G#%Q11r&   r  __main__)5r  concurrent.futuresr   
concurrentr   collections.abcr   r   r4   r   r   r  r  rS   rB   r1   r  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   TestCaser  r  r!  rK  rv  r  r  r   mainr)   r&   r$   <module>r     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HMMO r&   