
    <e&                         d Z ddlZddlZddlZddlmZ d Z G d dej                  Zedk    r ej	                     dS dS )zTests for asyncio/timeouts.py    N)tasksc                  .    t          j        d            d S )N)asyncioset_event_loop_policy     6/usr/lib/python3.11/test/test_asyncio/test_timeouts.pytearDownModuler
   
   s    !$'''''r   c                       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d Zd Zd Zd Zd Zd Zd Zd ZdS )TimeoutTestsc                 l  K   |                      t                    5  t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     |                                           d S N{Gz?
   )assertRaisesTimeoutErrorr   timeoutsleep
assertTrueexpiredselfcms     r	   test_timeout_basiczTimeoutTests.test_timeout_basic   so     |,, 	( 	(t,, ( ( ( ( ( ( (mB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	

%%%%%4   BA%B%
A/	/B2A/	3BB	Bc                   K   t          j                    }|                     t                    5  |                                dz   }t          j        |          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     |                                           | 	                    ||
                                           d S r   )r   get_running_loopr   r   time
timeout_atr   r   r   assertEqualwhen)r   loopdeadliner   s       r	   test_timeout_at_basicz"TimeoutTests.test_timeout_at_basic   s     '))|,, 	( 	(yy{{T)H)(33 ( ( ( ( ( ( (rmB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	

%%%27799-----s5   2B,"B=B,
B	B,B	B,,B03B0c                   K   t          j                    }d}|                     t                    5  |                                dz   }t          j        |          4 d {V }	 t          j        |          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   n# t           j        $ r d} w xY wd d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     |           |                     |	                                           |                     |	                                           d S NFr   r   T)
r   r   r   r   r   r   r   CancelledErrorr   r   )r   r"   	cancelledr#   cm1cm2s         r	   test_nested_timeoutsz!TimeoutTests.test_nested_timeouts    s     '))	|,, 		 		yy{{T)H)(33       s&1(;; 0 0 0 0 0 0 0s%mB/////////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0-    $I                          		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		"""&&&&&&&&sq   2D$C'&B? B-B?-
B77B?:B7;B?>C'?CC'D'
C1	1D4C1	5DDDc                   K   t          j                    }d}|                     t                    5  t          j        d          4 d {V  	 t          j        d           d {V  n# t           j        $ r d} w xY w	 d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     |           d S r&   )r   r   r   r   r   r   r'   r   )r   r"   r(   s      r	   test_waiter_cancelledz"TimeoutTests.test_waiter_cancelled1   s     '))	|,, 	 	t,,        !-++++++++++-    $I ,                          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 		"""""sM   B0BA*)B*A==BB0
B	B0 B	!B00B47B4c                    K   t          j                    }|                                }t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   |                                }|                     |                                           |                     ||z
  d           |                     |	                                |           d S )Nr   r      )
r   r   r   r   r   assertFalser   
assertLessassertGreaterr!   r   r"   t0r   t1s        r	   test_timeout_not_calledz$TimeoutTests.test_timeout_not_called=   sd     '))YY[[?2&& 	& 	& 	& 	& 	& 	& 	&"-%%%%%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&YY[[&&&2q!!!27799b)))))   A11
A;>A;c                   K   t          j                    }|                                }t          j        d           4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   |                                }|                     |                                           |                     |                                           | 	                    ||z
  d           d S Nr   r/   )
r   r   r   r   r   r0   r   assertIsNoner!   r1   r3   s        r	   test_timeout_disabledz"TimeoutTests.test_timeout_disabledI   sb     '))YY[[?4(( 	& 	& 	& 	& 	& 	& 	&B-%%%%%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&YY[[&&&"''))$$$2q!!!!!r7   c                   K   t          j                    }|                                }t          j        d           4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   |                                }|                     |                                           |                     |                                           | 	                    ||z
  d           d S r9   )
r   r   r   r   r   r0   r   r:   r!   r1   r3   s        r	   test_timeout_at_disabledz%TimeoutTests.test_timeout_at_disabledU   sc     '))YY[[%d++ 	& 	& 	& 	& 	& 	& 	&r-%%%%%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&YY[[&&&"''))$$$2q!!!!!r7   c                 ~  K   t          j                    }|                                }|                     t                    5  t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                                }|                     |                                           | 	                    ||z
  d           |                     ||
                                cxk    o|k    nc            d S )Nr   r   r/   r   r   r   r   r   r   r   r   r   r1   r!   r3   s        r	   test_timeout_zerozTimeoutTests.test_timeout_zeroa   s     '))YY[[|,, 	( 	(q)) ( ( ( ( ( ( (RmB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( YY[[

%%%2q!!!bggii----2----.....6   B)B:B)
B	B)B	B))B-0B-c                 ~  K   t          j                    }|                                }|                     t                    5  t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                                }|                     |                                           | 	                    ||z
  d           |                     ||
                                cxk    o|k    nc            d S )Nr   r/   r?   r3   s        r	   test_timeout_zero_sleep_zeroz)TimeoutTests.test_timeout_zero_sleep_zerom   s     '))YY[[|,, 	' 	'q)) ' ' ' ' ' ' 'RmA&&&&&&&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' YY[[

%%%2q!!!bggii----2----.....rA   c                 ~  K   t          j                    }|                                }|                     t                    5  t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                                }|                     |                                           | 	                    ||z
  d           |                     ||
                                cxk    o|k    nc            d S )Nir   r/   r?   r3   s        r	   #test_timeout_in_the_past_sleep_zeroz0TimeoutTests.test_timeout_in_the_past_sleep_zeroy   s     '))YY[[|,, 	' 	's++ ' ' ' ' ' ' 'rmA&&&&&&&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' YY[[

%%%2q!!!bggii----2----.....rA   c                 $  K   |                      t                    5  t          j        d          4 d {V }t          # 1 d {V swxY w Y   	 d d d            n# 1 swxY w Y   |                     |                                           d S )Nr   )r   KeyErrorr   r   r0   r   r   s     r	   test_foreign_exception_passedz*TimeoutTests.test_foreign_exception_passed   s     x(( 	 	t,,                     	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	&&&&&s.   AA  
A
	
AA
	AA"%A"c                   K   d }|                      t                    5  t          j        d          4 d {V   |             d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                  ^   K   	 t          j        d           d {V  ddz   d S # ddz   w xY w)N   r   )r   r   r   r   r	   crashz=TimeoutTests.test_foreign_exception_on_timeout.<locals>.crash   sH      mA&&&&&&&&&!!s   % ,r   )r   ZeroDivisionErrorr   r   )r   rL   s     r	   !test_foreign_exception_on_timeoutz.TimeoutTests.test_foreign_exception_on_timeout   sf     	 	 	
 011 	 	t,,        egg                          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s4   A<AA<
A(	(A<+A(	,A<<B B c                   K   |                      t          j                  5  t          j        d          4 d {V }t          j                                                     t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     |                                           d S )Nr   )	r   r   r'   r   current_taskcancelr   r0   r   r   s     r	   1test_foreign_cancel_doesnt_timeout_if_not_expiredz>TimeoutTests.test_foreign_cancel_doesnt_timeout_if_not_expired   s     w566 	( 	(r** ( ( ( ( ( ( (b$&&--///mB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	&&&&&s5   B,A B=B,
B	B,B	B,,B03B0c                     K   d fd}t          j         |                      }| d {V                       |                                                                |                                           d S )Nreturnc                  "  K                         t                    5  t          j        d          4 d {V  t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S )NgMbP?r   r   r   r   r   r   r   s   r	   outerz<TimeoutTests.test_outer_task_is_not_cancelled.<locals>.outer   s`     ""<00 , ,"?511 , , , , , , , ,!-+++++++++, , , , , , , , , , , , , , , , , , , , , , , , , , ,, , , , , , , , , , , , , , , , , ,s4   BA&B&
A0	0B3A0	4BBB)rT   N)r   create_taskr0   r(   r   done)r   rX   tasks   `  r	    test_outer_task_is_not_cancelledz-TimeoutTests.test_outer_task_is_not_cancelled   s      	, 	, 	, 	, 	, 	,
 "5577++






))***		$$$$$r   c           	      (  K   |                      t                    5  t          j        d          4 d {V  |                      t                    5  t          j        d          4 d {V  t	          j        d           t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S )NgMb`?皙?r   rK   )r   r   r   r   r   r   rW   s    r	   test_nested_timeouts_concurrentz,TimeoutTests.test_nested_timeouts_concurrent   s     |,, 	/ 	/u-- / / / / / / / /&&|44 / /&s33 / / / / / / / /
4(((%mA........./ / / / / / / / / / / / / / / / / / / / / / / / / / // / / / / / / / / / / / / / // / / / / / / / / / / / / / / / / / / / / / / / / / /	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s|   DC)C./B/	C/
B99C<B9=C C)CC)CC)D)
C3	3D6C3	7DDDc           	      *  K   t          j                    }d|_        |                                }|                     t
                    5  t          j        d          4 d {V  |                     t
                    5  t          j        d          4 d {V  t          j        d           t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                                }|                     ||cxk    o|dz   k    nc            d S )Nr   r^   r   rK   )	r   r   slow_callback_durationr   r   r   r   r   r   )r   r"   r4   r5   s       r	   test_nested_timeouts_loop_busyz+TimeoutTests.test_nested_timeouts_loop_busy   s      '))&(#YY[[|,, 	( 	(s++ ( ( ( ( ( ( ( (&&|44 / /&t44 / / / / / / / /
3%mA........./ / / / / / / / / / / / / / / / / / / / / / / / / / // / / / / / / / / / / / / / / mB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( YY[[b****BF****+++++s~   E&D1C:/C	C:
C''C:*C'+C:.D1:C>>D1C>D1E1
D;	;E>D;	?EEEc                   K   t          j                    }|                                |                                dz   dz   }fd}t          j         |                      } d {V }|                     |                                           |                    |           |                     |                                |           |                    d            |                     |                                           |	                                 | 
                    t           j                  5  | d {V  d d d            n# 1 swxY w Y   |                     |                                           d S )Nr      c                     K   t          j                  4 d {V }                     |            t          j        d           d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S )N2   )r   r   
set_resultr   )r   	deadline1futs    r	   fz'TimeoutTests.test_reschedule.<locals>.f   s     ))44 ( ( ( ( ( ( (r"""mB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   0A!!
A+.A+)r   r   create_futurer   rY   r    r!   
rescheduler:   rQ   r   r'   r0   r   )r   r"   	deadline2rj   r[   r   rh   ri   s         @@r	   test_reschedulezTimeoutTests.test_reschedule   s     '))  ""IIKK"$	N		( 	( 	( 	( 	( 	(
 "1133''YYYYYYI...
i   I...
d"''))$$$w566 	 	JJJJJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	&&&&&s   	EE"Ec                    K   t          j        d          4 d {V }|                     t          |          d           d d d           d {V  d S # 1 d {V swxY w Y   d S )Nr   z"<Timeout \[active\] when=\d+\.\d*>)r   r   assertRegexreprr   s     r	   test_repr_activezTimeoutTests.test_repr_active   s     ?2&& 	N 	N 	N 	N 	N 	N 	N"T"XX'LMMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N   $A
A!Ac                 d  K   |                      t                    5  t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     t          |          d           d S )Nr   r   z<Timeout [expired]>)r   r   r   r   r   r    rq   r   s     r	   test_repr_expiredzTimeoutTests.test_repr_expired   sr     |,, 	( 	(t,, ( ( ( ( ( ( (mB'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	b#899999r   c                    K   t          j        d          4 d {V }t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   |                     t	          |          d           d S )Nr   r   z<Timeout [finished]>)r   r   r   r    rq   r   s     r	   test_repr_finishedzTimeoutTests.test_repr_finished   s	     ?2&& 	# 	# 	# 	# 	# 	# 	#"-"""""""""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	b#9:::::s   A


AAc                    K   t          j        d           4 d {V }|                     t          |          d           d d d           d {V  d S # 1 d {V swxY w Y   d S )Nz<Timeout [active] when=None>)r   r   r    rq   r   s     r	   test_repr_disabledzTimeoutTests.test_repr_disabled   s     ?4(( 	H 	H 	H 	H 	H 	H 	HBT"XX'FGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hrs   c                 V  K   |                      t                    5  t          j        d          4 d {V  	 t          j        d           d {V  |                      t                    5  t          j        d          4 d {V  t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   n# |                      t                    5  t          j        d          4 d {V  t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            w # 1 swxY w Y   w xY wd d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   rK   r   rV   rW   s    r	   test_nested_timeout_in_finallyz+TimeoutTests.test_nested_timeout_in_finally   s     |,, 	4 	4t,, 4 4 4 4 4 4 4 44!-***********<88 4 4#*?4#8#8 4 4 4 4 4 4 4 4")-"3"333333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4**<88 4 4#*?4#8#8 4 4 4 4 4 4 4 4")-"3"333333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   FF CF .C	B6	$C6
C  CC CF CF CF E+:EE0E
EEEEE+E##E+&E#'E++F .F 
F
	
FF
	FF"%F"c           	        K   	 t          j                                                     t          j        d           d {V  n# t           j        $ r Y nw xY w|                     t                    5  t          j        d          4 d {V  t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S # |                     t                    5  t          j        d          4 d {V  t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            w # 1 swxY w Y   w xY w)NrK   g        )r   rP   rQ   r   r'   r   r   r   rW   s    r	   test_timeout_after_cancellationz,TimeoutTests.test_timeout_after_cancellation   s     	+ ""))+++-""""""""""% 	 	 	D	 ""<00 + +"?3// + + + + + + + +!-*********+ + + + + + + + + + + + + + + + + + + + + + + + + + ++ + + + + + + + + + + + + + + + + +""<00 + +"?3// + + + + + + + +!-*********+ + + + + + + + + + + + + + + + + + + + + + + + + + ++ + + + + + + + + + + + + + + +s   ?A C& AC& AC& 3CB;)C;
C	CC		CC C&E2E&E		7E&	
EE&EE&E2&E**E2-E*.E2c           	        K   	 t          j                                                     t          j        d           d {V  n# t           j        $ r Y nw xY w|                     t           j                  5  t          j        d          4 d {V  t          j                                                     t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S # |                     t           j                  5  t          j        d          4 d {V  t          j                                                     t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            w # 1 swxY w Y   w xY w)NrK   g      ?r/   )r   rP   rQ   r   r'   r   r   rW   s    r	   )test_cancel_in_timeout_after_cancellationz6TimeoutTests.test_cancel_in_timeout_after_cancellation  sW     		+ ""))+++-""""""""""% 	 	 	D	 ""7#9:: + +"?3// + + + + + + + +(**11333!-*********+ + + + + + + + + + + + + + + + + + + + + + + + + + ++ + + + + + + + + + + + + + + + + +""7#9:: + +"?3// + + + + + + + +(**11333!-*********+ + + + + + + + + + + + + + + + + + + + + + + + + + ++ + + + + + + + + + + + + + + +s   ?A D AD AD 8DA C%D%
C/	/D2C/	3DD
D G0F:A F	F:
F''F:*F'+F:.G:F>>GF>Gc                 x  K   |                      t          j                  5 }t          j        d          4 d {V  t          j        d           d {V  d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |j        j        }t          |t          j                  sJ d S )Nr   rK   )	r   r   r   r   r   	exception	__cause__
isinstancer'   )r   exccauses      r	   test_timeout_exception_causez)TimeoutTests.test_timeout_exception_cause  s{     w344 	'q)) ' ' ' ' ' ' ' 'mA&&&&&&&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' '%!78888888s4   BA*B*
A4	4B7A4	8BBBN)__name__
__module____qualname__r   r$   r+   r-   r6   r;   r=   r@   rC   rE   rH   rN   rR   r\   r_   rb   rn   rr   ru   rw   ry   r{   r}   r   r   r   r   r	   r   r      s       & & &. . .' ' '"
# 
# 
#
* 
* 
*
" 
" 
"
" 
" 
"
/ 
/ 
/
/ 
/ 
/
/ 
/ 
/' ' '  ' ' '	% 	% 	%/ / /, , ,&' ' '4N N N: : :; ; ;H H H4 4 4	+ 	+ 	+
+ 
+ 
+9 9 9 9 9r   r   __main__)
__doc__unittestr   r   r   r
   IsolatedAsyncioTestCaser   r   mainr   r   r	   <module>r      s    # #         ( ( (I9 I9 I9 I9 I983 I9 I9 I9X zHMOOOOO r   