
    <|h                        d dl Z d dlmZ d dlZd dlZd dlZd dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d dlmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d dej*                        Zedk(  r ej0                          yy)    N)sleep)Timeout)get_hub)
SMALL_TICK)flakyc                       e Zd Zy)ErrorN)__name__
__module____qualname__     ]/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/tests/test__api_timeout.pyr	   r	   %   s    r   r	   c                   "    e Zd ZdZd Zd Zd Zy)_UpdateNowProxyr   c                     || _         y Nloopselfr   s     r   __init__z_UpdateNowProxy.__init__-   	    	r   c                 .    t        | j                  |      S r   )getattrr   )r   names     r   __getattr__z_UpdateNowProxy.__getattr__0   s    tyy$''r   c                 b    | xj                   dz  c_         | j                  j                          y )N   )update_now_callsr   
update_nowr   s    r   r!   z_UpdateNowProxy.update_now3   s#    "		r   N)r
   r   r   r    r   r   r!   r   r   r   r   r   )   s    (r   r   c                       e Zd Zd Zy)_UpdateNowWithTimerProxyc                     t        |       S r   )_Timer)r   _args_kwargss      r   timerz_UpdateNowWithTimerProxy.timer9   s    d|r   N)r
   r   r   r)   r   r   r   r$   r$   7   s    r   r$   c                   ,    e Zd ZdZdZd Zd Zd Zd Zy)r&   Fc                     || _         y r   r   r   s     r   r   z_Timer.__init__A   r   r   c                 v    |j                  d      r| j                  j                          dx| _        | _        y )NupdateT)getr   r!   pendingactive)r   r'   kwargss      r   startz_Timer.startD   s,    ::hII  "%))t{r   c                      dx| _         | _        y )NF)r0   r/   r"   s    r   stopz_Timer.stopI   s    %**dlr   c                      y)zDoes nothingNr   r"   s    r   closez_Timer.closeL   s    r   N)	r
   r   r   r/   r0   r   r2   r4   r6   r   r   r   r&   r&   <   s     GF*
+r   r&   c                       e Zd Zd Zd Z ej                  d       ej                  d       ej                  e	e
f      d                      Zd Z ej                         d        Zy)Testc                 8   t               }|j                  }t        |      }||_        	 t        t        dz        5 }| j                  |j                         d d d        ||_        | j                  d|j                         y # 1 sw Y   -xY w# ||_        w xY w)N   r   )	r   r   r$   r   DELAY
assertTruer/   assertEqualr    )r   hubr   proxyts        r   test_timeout_calls_update_nowz"Test.test_timeout_calls_update_nowR   s    ixx(.	# +q		*+ CHE223+ + CHs"   B BB B	B 	Bc                     t               }|j                  }t        |      }||_        	 t        d       ||_        | j	                  d|j
                         y # ||_        w xY w)Ng{Gz?r   )r   r   r   r   r=   r    )r   r>   r   r?   s       r   test_sleep_calls_update_nowz Test.test_sleep_calls_update_now`   sW    ixx%	$KCHE223 CHs   A 	A"z/Timing is flaky, especially under Py 3.4/64-bitc                     t        t        dz        }| j                  |j                  |       |5  | j	                  |j                  |       t        t               d d d        | j                  |j                  |       t        t        dz         | j                  t               5 }t        t              5 }t        t        dz         d d d        d d d        | j                  j                  |       | j                  t              5  t        t        t        d            5  t        t        dz         d d d        d d d        | j                  t              5  t        t        t              5  t        t        dz         d d d        d d d        	 ddz   t        d      # 1 sw Y   LxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   _xY w# 1 sw Y   cxY w# t        $ r~ | j                  t              5  t        t        t        j                         d         5  t        t        dz         t        d      # 1 sw Y   t        d      xY w# 1 sw Y   nxY wY nw xY wt        t              5 }|j                          t        t        dz         d d d        n# 1 sw Y   nxY wd}t!        j                          }t        |d      5  t        |dz         d d d        n# 1 sw Y   nxY wt!        j                          |z
  }| j#                  |d|dz         t        d       5  t        t               d d d        n# 1 sw Y   nxY wt        t               y )	Nr:   
   zOperation takes way too longr   r   should not get thereg?F)r   r;   assertFalser/   r<   r   assertRaisesassertIs	exceptionIOError
ValueErrorAssertionErrorZeroDivisionErrorsysexc_infocanceltimeassertTimeWithinRange)r   r@   excr)   XDELAYr2   deltas          r   test_apizTest.test_apim   s   
 EAIA& 	OOAIIq)%L	 	A&eai w' 	"3 "1ebj!"	" 	cmmQ' w' 	"(F GH "ebj!"	"
 z* 	"
+ "ebj!"	"
		9E !!788E	 	" "	" 	"" "	" 	"" "	" 	" ! 	=""#45 =UCLLN1$56 A%"*%()?@@A %%;<<	= = =	= U^ 	uLLN%!)	 	 	
 		VU# 	&1*	 	 			e#""5!VaZ8 T] 	%L	 	 	es   ,F'(G 8F4G G&G9GG03G$G0G< 'F14F=	9G  G	G	GG!$G-	)G00G9<J&I4 II1#I44I=	9JJ#KK
/LLM$$M-c                    t               }t        j                  |      }t        t        dz  |      5  t        t               d d d        ~t        j                          | j                   |       |       y # 1 sw Y   6xY w)Nr:   )	r	   weakrefrefr   r;   r   gccollectrG   )r   errerr_refs      r   test_refzTest.test_ref   s_    g++c"UQY$ 	%L	


G,		 	s   A88Bc                    t        t        d      5  t        t        dz  d      5  t        t        dz  dz         d d d        t        d      # 1 sw Y   t        d      xY w# 1 sw Y   nxY wt        t              5 }t        t        dz        5 }| j	                  t               5 }t        t        dz         d d d        n# 1 sw Y   nxY w| j                  j                  |       | j                  |j                  |       | j                  |j                  |       d d d        n# 1 sw Y   nxY w| j                  j                         d d d        n# 1 sw Y   nxY wt        t        dz        5 }t        t              5 }| j	                  t               5 }t        t        dz         d d d        n# 1 sw Y   nxY w| j                  j                  |       | j                  |j                  |       | j                  |j                  |       d d d        n# 1 sw Y   nxY wd d d        n# 1 sw Y   nxY w| j                  j                         y )NFrE         rF      )
r   r;   r   rM   rH   rI   rJ   rG   r/   r<   )r   t1t2rT   s       r   test_nested_timeoutzTest.test_nested_timeout   s   UE" 	9U+ &eai"n%& !788& !788	9 	9
 U^ 		)r$ 0&&w/ &3%"*%& & &cmmR0  R0

B/0 0 0 RZZ(		) 		) 		) URZ  	1B 12&&w/ &3%"*%& & &cmmR0

B/  R01 1 1	1 	1 	1 	$s   A$AA$A!	A$$A-?ED-(C;	D-C	AD-$	E-D6	2"EE&;H;H&!F=4	H&=GAH&	H;&H/	+H;;IN)r
   r   r   rA   rC   	greentestskipOnAppVeyorskipOnPyPy3OnCIreraises_flaky_timeoutr   rM   rW   r_   r   reraises_flaky_race_conditionrf   r   r   r   r8   r8   P   s    4
4 YOPYPQ%Y%%w&?@8 A R Q8t- )U((*% +%r   r8   __main__)rO   gevent.testingtestingrg   rY   rR   r[   geventr   r   r   gevent.testing.timingr   r;   r   	Exceptionr	   objectr   r$   r&   TestCaser8   r
   mainr   r   r   <module>ru      s   ,  "   	    6  	I 	f  
V (~%9 ~%B zINN r   