
    dafD*                         d dl Z d dlZd dlZd dlmZ d ZdZ G d d      Z G d dej                        Z	 G d	 d
ej                        Z
edk(  r ej                          yy)    N)supportc                  .    t        j                  d        y N)asyncioset_event_loop_policy     9/root/Python-3.12.4/Lib/test/test_asyncio/test_waitfor.pytearDownModuler      s    !!$'r	   g-C6?c                        e Zd ZdZdZd Zd Zy)SlowTaskz? Task will run for this defined time, ignoring cancel requests 皙?c                     d| _         y )NF)exitedselfs    r
   __init__zSlowTask.__init__   s	    r	   c                   K   t        j                         | j                  z   }	 |t        j                         z
  }|dk  r		 d| _        y 	 t        j                  |       d {    D7 # t        j
                  $ r Y w xY ww)NTr   )time	monotonicTASK_TIMEOUTr   sleepCancelledErrorr   )r   exitattosleeps      r
   runzSlowTask.run   s|     !D$5$55t~~//G!| mmG,,,  -)) s<   ABA+ #A)$A+ (B)A+ +B>B BBN)__name__
__module____qualname____doc__r   r   r   r   r	   r
   r   r      s    ILr	   r   c                   r    e 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d Zd Zd Zy)AsyncioWaitForTestc                 |  K   t               }t        j                  t        j                  |j	                         |j
                  dz              }t        j                  d       d {    |j                          t        j                  |h       d {    | j                  |j                         y 7 N7 "w)N   r   )r   r   create_taskwait_forr   r   r   cancelwait
assertTruer   )r   twaitfortasks      r
   test_asyncio_wait_for_cancelledz2AsyncioWaitForTest.test_asyncio_wait_for_cancelled*   s     J))QUUWannq&89;mmAllK=)))!	 	)s$   A'B<)B8*-B<B:!B<:B<c                    K   t               }	 t        j                  |j                         |j                  dz         d {    | j                  |j                         y 7  # t        j
                  $ r Y 3w xY ww)Nr$   )r   r   r&   r   r   TimeoutErrorr)   r   )r   r*   s     r
   test_asyncio_wait_for_timeoutz0AsyncioWaitForTest.test_asyncio_wait_for_timeout5   sf     J	""1557ANNQ,>??? 	!	 @## 		s:   A>4A% A#A% A>#A% %A;8A>:A;;A>c                   K   t        j                         }|j                         }|j                  d       t        j                  |d       d {   }| j                  |d       | j                  |j                                y 7 6w)Ndoner   )r   get_running_loopcreate_future
set_resultr&   assertEqualr)   r1   )r   loopfutrets       r
   2test_wait_for_timeout_less_then_0_or_0_future_donezEAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_future_done?   sj     '')  "v$$S!,,f%
# -s   AB
B7B
c                    K   dfd}| j                  t        j                        5  t        j                   |       d       d {    d d d        | j	                  d       y 7 # 1 sw Y   xY ww)NFc                     K   d y w)NTr   )foo_starteds   r
   fooz_AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_started.<locals>.fooM   s     Ks   r   )assertRaisesr   r.   r&   r5   )r   r=   r<   s     @r
   ?test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedzRAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedJ   sk     	 w334 	-""35!,,,	- 	e, -	- 	-s.   'A7A+	A)
A+A7)A++A40A7c                 Z  K   t        j                         }dD ]  }| j                  |      5  d |j                         fd}t        j                   |             } d {    | j                  t         j                        5  t        j                  ||       d {    d d d        | j                  |j                                | j                  |j                                | j                  d       d d d         y 7 7 i# 1 sw Y   hxY w# 1 sw Y   xY ww)N)r   timeoutc                     K   d j                  d        	 t        j                  d       d {    d y7 # d w xY ww)NT
   Fr1   )r4   r   r   )foo_runningstarteds   r
   r=   zFAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0.<locals>.foo^   sD     "&K&&t,,%mmB///&+! 0&+s#   A: 8: A: >AF)r   r2   subTestr3   r%   r>   r.   r&   r)   r1   	cancelledr5   )r   r6   rC   r=   r7   rF   rG   s        @@r
   &test_wait_for_timeout_less_then_0_or_0z9AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0V   s     '') 	5Gg. 5",,." ))#%0&&w';';< 9!**38889 
+0  e4/5 5	5   99 9#5 5sY   ,D+8D(D)#DD&D
'D+ADD+DDDDD(	#D+c                   K   d fd}t        j                   |             }| j                  t         j                        5  t        j                  |d       d {    d d d        | j                  |j                                | j                  |j                                | j                  d       y 7 ]# 1 sw Y   \xY ww)Nc                     K   d 	 t        j                  t        j                         d {    d y7 # d w xY ww)NTFr1   )r   r   r   LONG_TIMEOUT)rF   s   r
   r=   z-AsyncioWaitForTest.test_wait_for.<locals>.foov   s<     K$mmG$8$8999# :#s    >&7 57 >7 ;>皙?F)	r   r%   r>   r.   r&   r)   r1   rI   r5   )r   r=   r7   rF   s      @r
   test_wait_forz AsyncioWaitForTest.test_wait_fors   s     	 !!#%(w334 	-""3,,,	-
#(e,	 -	- 	-s1   AC
B>B<B>#AC
<B>>CC
c                    K   d }t        j                   |       d        d {   }| j                  |d       y 7 w)Nc                     K   ywNr1   r   r   r	   r
   coroz7AsyncioWaitForTest.test_wait_for_blocking.<locals>.coro   	        rB   r1   r   r&   r5   )r   rS   ress      r
   test_wait_for_blockingz)AsyncioWaitForTest.test_wait_for_blocking   s9     	 $$TVT::f% ;   #?=?c                    K   t        j                         }|j                         }t        j                  |d      }|j	                  |j
                  d       | d {   }| j                  |d       y 7 w)Nr   rB   ok)r   r2   r3   r&   	call_soonr4   r5   )r   r6   r7   taskrW   s        r
   test_wait_for_race_conditionz/AsyncioWaitForTest.test_wait_for_race_condition   sb     '')  "S1s~~t,jd# s   AA9A7 A9c                     K    fd}t        j                   |       d       d {   } j                  |d       y 7 w)Nc                     K    j                  t        j                        5  t        j                  d       d {    d d d        y7 # 1 sw Y   yxY ww)N   )r>   r   r   r   r   s   r
   innerzKAsyncioWaitForTest.test_wait_for_cancellation_race_condition.<locals>.inner   sH     ""7#9#9: 'mmA&&&' ''s,    AAA
A	A
AAA{Gz?rB   ra   rV   )r   rb   results   `  r
   )test_wait_for_cancellation_race_conditionz<AsyncioWaitForTest.test_wait_for_cancellation_race_condition   s:     	
 ''==# >s   %AA Ac                   K   dfd}t        j                   |             }| j                  t         j                        5 }t        j                  |t
               d {    d d d        | j                         j                  j                  }| j                  t        |      t         j                         y 7 ]# 1 sw Y   \xY ww)NFc                     K   	 t        j                  d       d {    d y 7 # t         j                  $ r$ t        j                  t               d {  7    w xY w# d w xY wwNrE   Tr   r   r   _EPSILON	task_dones   r
   rb   zKAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation.<locals>.inner   s[     !mmB'''
 !	 ()) mmH--- !	=   A(' %' A(' /AAAA! !A%%A(rB   )r   r%   r>   r.   r&   rj   r)   	exception__context__r5   typer   )r   rb   
inner_taskcmchainedrl   s        @r
   )test_wait_for_waits_for_task_cancellationz<AsyncioWaitForTest.test_wait_for_waits_for_task_cancellation   s     		! ((1
w334 	A"":x@@@	A 		",,**g(>(>?	 A	A 	As1   ACC#C$C(ACCCCc                 F  K   dfd}| j                  t        j                        5 } |        d {    d d d        | j                         j                  j
                  }| j                  t        |      t        j                         y 7 ]# 1 sw Y   \xY ww)NFc                     K   fd} t        j                   |              }t        j                  t               d {    t        j                  |d       d {    y 7 $7 w)Nc                     K   	 t        j                  d       d {    d y 7 # t         j                  $ r$ t        j                  t               d {  7    w xY w# d w xY wwrh   ri   rk   s   r
   rb   zdAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo.<locals>.inner   s[     %!--+++
 !%I ,-- !--111 !%Irm   r   rB   )r   r%   r   rj   r&   )rb   rq   rl   s     r
   r=   zUAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo   sQ     % !,,UW5J--)))"":q999 *9s"   <A(A$ A(A&A(&A()	r>   r   r.   r)   rn   ro   r5   rp   r   )r   r=   rr   rs   rl   s       @r
   5test_wait_for_waits_for_task_cancellation_w_timeout_0zHAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0   s     		: w334 	%KK	 		",,**g(>(>?	 	 	s,   'B!BBBAB!BBB!c                    K    G d dt               fd}| j                        5   |        d {    d d d        y 7 # 1 sw Y   y xY ww)Nc                       e Zd Zy)]AsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.FooExceptionN)r   r   r   r   r	   r
   FooExceptionr{      s    r	   r|   c                     K   fd} t        j                   |              }t        j                  |t               d {    y 7 w)Nc                  \   K   	 t        j                  d       d {     7 #  xY ww)Nr   r   r   )r|   s   r
   rb   zcAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo.<locals>.inner   s0     '!--,,,&& -&&s    ,& $& ,& ),rB   )r   r%   r&   rj   )rb   rq   r|   s     r
   r=   zTAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo   s6     ' !,,UW5J"":x@@@s   >A	AA	)	Exceptionr>   )r   r=   r|   s     @r
   4test_wait_for_reraises_exception_during_cancellationzGAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation   sO     	9 			A |, 	%KK	 		 	s+   &AAAA	AAA	Ac                   K   t        j                         fd}t        j                   |             }t        j                  t        j                  ||            }j	                  |j
                         | j                  t         j                        5  | d {    d d d        | j                  |j                                y 7 ,# 1 sw Y   +xY ww)Nc                  F   K   j                         } |  d {    y 7 wr   )r3   )r7   r6   s    r
   blocking_coroutinezDAsyncioWaitForTest._test_cancel_wait_for.<locals>.blocking_coroutine   s     $$&CIIs   !!)
r   r2   r%   r&   r\   r'   r>   r   r)   rI   )r   rC   r   r]   r(   r6   s        @r
   _test_cancel_wait_forz(AsyncioWaitForTest._test_cancel_wait_for   s     '')	
 ""#5#78""7#3#3D'#BCt{{#w556 	JJ	 	() 	 	s0   BCC C!C%(CCCCc                 B   K   | j                  d        d {    y 7 wr   r   r   s    r
   test_cancel_blocking_wait_forz0AsyncioWaitForTest.test_cancel_blocking_wait_for        ((...   c                 B   K   | j                  d       d {    y 7 w)Ng      N@r   r   s    r
   test_cancel_wait_forz'AsyncioWaitForTest.test_cancel_wait_for   r   r   c                    K   d }t        j                   |       d       d {   }| j                  |d       y 7 w)Nc                  ~   K   	 t        j                  d       d {    y 7 # t         j                  $ r Y yw xY ww)NrE   *   )r   r   r   r   r	   r
   	return_42zEAsyncioWaitForTest.test_wait_for_cancel_suppressed.<locals>.return_42  s4     mmB''')) s(   =$ "$ =$ :=:=rN   rB   r   rV   )r   r   rW   s      r
   test_wait_for_cancel_suppressedz2AsyncioWaitForTest.test_wait_for_cancel_suppressed   s9     	 $$Y[#>>b! ?rY   c                 B  K   d }t        j                   |             dfd}t        j                   |             }| j                  |j                                t        j                  d       d {    |j                          | j                  t         j                        5  | d {    d d d        | j                  j                                | j                   d {   d       | j                         y 7 7 Y# 1 sw Y   XxY w7 +w)Nc                     K   ywrR   r   r   r	   r
   rb   z:AsyncioWaitForTest.test_wait_for_issue86296.<locals>.inner  rT   rU   Fc                     K   t        j                   d       d {    t        j                  d       d {    dy 7 $7 	w)Nd   rB   ra   T)r   r&   r   )rq   reached_ends   r
   wait_for_corozBAsyncioWaitForTest.test_wait_for_issue86296.<locals>.wait_for_coro  s=     "":s;;;--"""K <"s   AAAAAAr   r1   )
r   r%   assertFalser1   r   r'   r>   r   r)   r5   )r   rb   r   r]   rq   r   s       @@r
   test_wait_for_issue86296z+AsyncioWaitForTest.test_wait_for_issue86296  s     
	 ((1
	 ""=?3%mmAw556 	JJ	
)*z)62% 	 	 	 *sH   A7D;D<3D/D5D6D:7D1D2DDDDN)r   r   r   r,   r/   r9   r?   rJ   rO   rX   r^   re   rt   rx   r   r   r   r   r   r   r   r	   r
   r"   r"   (   sY    	""	$
-5:-*&$$@,@2$*&//" &r	   r"   c                       e Zd Zd Zd Zd Zy)WaitForShieldTestsc                 P  K   d }t        j                   |             }| j                  t         j                        5  t        j                  |      }t        j
                  |d       d {    d d d        | j                  |j                                | j                  |j                                | j                  j                                t        j                  d       d {    | j                  |j                                y 7 # 1 sw Y   xY w7 2w)Nc                  J   K   t        j                  d       d {    y7 w)Nrc   r1   r   r   r	   r
   rS   z2WaitForShieldTests.test_zero_timeout.<locals>.coro1  s      --%%% &   #!#r   rB   rN   )r   r%   r>   r.   shieldr&   r   r1   rI   r)   r   )r   rS   r]   shielded_tasks       r
   test_zero_timeoutz$WaitForShieldTests.test_zero_timeout*  s     	 ""46*w334 	=#NN40M""=!<<<	=
 	%)*//12 mmC   		$ =	= 	= 	!s;   =D&0D/D0D4A=D&1D$2$D&DD!D&c                 $  K   d }t        j                   |             }t        j                  t        j                  |      d        d {    | j	                  |j                                | j                  | d {   d       y 7 >7 w)Nc                  J   K   t        j                  d       d {    y7 wNrN   r1   r   r   r	   r
   rS   z2WaitForShieldTests.test_none_timeout.<locals>.coroG        --$$$ %r   rB   r1   )r   r%   r&   r   r)   r1   r5   r   rS   r]   s      r
   test_none_timeoutz$WaitForShieldTests.test_none_timeoutD  sn     	 ""46*w~~d3TBBB		$tV, 	C $s$   ABB3BBBBc                   K   d }t        j                   |             }| j                  t         j                        5  t        j                  t        j
                  |      d       d {    d d d        | j                  |j                                | j                  |j                                | j                  | d {   d       y 7 e# 1 sw Y   dxY w7 w)Nc                  J   K   t        j                  d       d {    y7 wr   r   r   r	   r
   rS   z6WaitForShieldTests.test_shielded_timeout.<locals>.coroS  r   r   rc   rB   r1   )
r   r%   r>   r.   r&   r   r   r1   rI   r5   r   s      r
   test_shielded_timeoutz(WaitForShieldTests.test_shielded_timeoutQ  s     	 ""46*w334 	G""7>>$#7FFF	G 	%)*tV,	 G	G 	G
 $s;   =C#.C-C.C2AC#C!	
C#CCC#N)r   r   r   r   r   r   r   r	   r
   r   r   (  s    %4--r	   r   __main__)r   unittestr   testr   r   rj   r   IsolatedAsyncioTestCaser"   r   r   mainr   r	   r
   <module>r      si       (  .}&99 }&@5-99 5-p zHMMO r	   