
    R?grB                        S SK r S SKJr  S SKrS SKrS SKJrJr  S SKJ	r	  S SK
JrJr   " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r\S:X  a  \R(                  " 5         gg)    N)	timedelta)genlocks)TimeoutError)gen_testAsyncTestCasec                      ^  \ rS rSrU 4S jrS rS rS r\S 5       r	S r
S rS	 r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrU =r$ )ConditionTest   c                 0   > [         TU ]  5         / U l        g N)supersetUphistory)self	__class__s    9/usr/lib/python3/dist-packages/tornado/test/locks_test.pyr   ConditionTest.setUp   s        c                 <   ^ ^^ UUU 4S jnTR                  U5        g)z=Record the resolution of a Future returned by Condition.wait.c                    > TR                  5       (       d  TR                  R                  S5        g TR                  R                  T5        g )Ntimeout)resultr   append)_futurekeyr   s    r   callback+ConditionTest.record_done.<locals>.callback   s2    ==??##I.##C(r   N)add_done_callback)r   r   r   r   s   ``` r   record_doneConditionTest.record_done   s    	) 	  *r   c                 n    U R                   R                  U R                  5        U R                  5         g)zRun all queued callbacks on the IOLoop.

In these tests, this method is used after calling notify() to
preserve the pre-5.0 behavior in which callbacks ran
synchronously.
N)io_loopadd_callbackstopwaitr   s    r   loop_brieflyConditionTest.loop_briefly(   s#     	!!$)),		r   c                     [         R                  " 5       nU R                  S[        U5      5        U R	                  S[        U5      5        UR                  5         U R                  S[        U5      5        g )N	Conditionwaiters)r   r,   assertInreprassertNotInr'   r   cs     r   	test_reprConditionTest.test_repr2   sO    OOk47+DG,	ia)r   c              #      #    [         R                  " 5       nU R                  R                  SUR                  5        UR                  5       v   g 7f)N{Gz?)r   r,   r$   
call_laternotifyr'   r1   s     r   test_notifyConditionTest.test_notify9   s4     OOahh/ffhs   AAc                    [         R                  " 5       nU R                  UR                  5       S5        U R                  UR                  5       S5        UR	                  S5        U R                  5         U R                  R                  S5        UR	                  S5        U R                  5         U R                  R                  S5        U R                  / SQU R                  5        g )Nwait1wait2   notify1notify2)r<   r?   r=   r@   )	r   r,   r!   r'   r8   r)   r   r   assertEqualr1   s     r   test_notify_1ConditionTest.test_notify_1?   s    OO7+7+	I&	I&A4<<Pr   c                 l   [         R                  " 5       n[        S5       H#  nU R                  UR	                  5       U5        M%     UR                  S5        U R                  5         U R                  [        [        S5      5      U R                  5        UR                  S5        U R                  5         U R                  [        [        S5      5      U R                  5        UR                  S5        U R                  5         U R                  [        [        S5      5      U R                  5        g )N      r>         )
r   r,   ranger!   r'   r8   r)   rA   listr   r   r2   is      r   test_notify_nConditionTest.test_notify_nK   s    OOqAQVVXq)  	
 	eAh6	eAh6	eAh6r   c                 l   [         R                  " 5       n[        S5       H#  nU R                  UR	                  5       U5        M%     UR                  5         U R                  5         U R                  R                  S5        U R                  [        [        S5      5      S/-   U R                  5        g )NrG   
notify_all)r   r,   rI   r!   r'   rP   r)   r   r   rA   rJ   rK   s      r   test_notify_allConditionTest.test_notify_all\   s    OOqAQVVXq)  	
L) 	eAh<.8$,,Gr   c              #     #    [         R                  " 5       nUR                  [        SS95      nU R                  R                  SUR                  5        [        R                  " S5      v   U R                  Uv 5        g 7f)Nr6   seconds{Gz?Q?)
r   r,   r'   r   r$   r7   r8   r   sleepassertFalser   r2   r'   s      r   test_wait_timeoutConditionTest.test_wait_timeouth   sZ     OOvvi-.ahh/iio*&s   B Bc              #      #    [         R                  " 5       nU R                  R                  SUR                  5        UR                  [        SS95      n[        R                  " S5      v   Uv   g 7f)Nr6   rV   rT   rW   )	r   r,   r$   r7   r8   r'   r   r   rX   rZ   s      r   test_wait_timeout_preempted)ConditionTest.test_wait_timeout_preemptedp   sQ     OO 	ahh/vvi-.iio
s   A1A3c              #     #    [         R                  " 5       nU R                  UR                  5       S5        U R                  UR                  [	        SS95      S5        U R                  UR                  5       S5        U R                  UR                  5       S5        [
        R                  " S5      v   U R                  S/U R                  5        UR                  S5        [
        R                  " S5      v   U R                  / S	QU R                  5        U R                  / S	QU R                  5        UR                  5         S v   U R                  / S
QU R                  5        g 7f)Nr   r6   rT   r>   rH   rF   rV   r   r   r   rH   )r   r   rH   rF   )
r   r,   r!   r'   r   r   rX   rA   r   r8   r1   s     r   test_notify_n_with_timeout(ConditionTest.test_notify_n_with_timeoutz   s      OO1%	$ 78!<1%1% iio)dll3	iio*DLL9*DLL9	
-t||<s   E+E-c              #     #    [         R                  " 5       nU R                  UR                  5       S5        U R                  UR                  [	        SS95      S5        U R                  UR                  5       S5        [
        R                  " S5      v   U R                  S/U R                  5        UR                  5         S v   U R                  / SQU R                  5        g 7f)	Nr   r6   rT   r>   rH   rV   r   ra   )
r   r,   r!   r'   r   r   rX   rA   r   rP   r1   s     r   test_notify_all_with_timeout*ConditionTest.test_notify_all_with_timeout   s     OO1%	$ 78!<1% iio)dll3	*DLL9s   C&C(c              #   X  ^#    [         R                  " 5       m[        S5       Vs/ s H'  n[        R                  " TR                  5       5      PM)     nnUS   R                  U4S j5        TR                  S5        S v   U R                  [        S U 5       5      5        g s  snf 7f)NrF   r>   c                 $   > TR                  5       $ r   )r8   )r   r2   s    r   <lambda>2ConditionTest.test_nested_notify.<locals>.<lambda>   s    qxxzr   rH   c              3   @   #    U  H  oR                  5       v   M     g 7fr   done).0fs     r   	<genexpr>3ConditionTest.test_nested_notify.<locals>.<genexpr>   s     6gFFHHg   )
r   r,   rI   asyncioensure_futurer'   r    r8   
assertTrueall)r   r   futuresr2   s      @r   test_nested_notify ConditionTest.test_nested_notify   s      OO =B!HEHq7((2HE 	
$$%9:	6g667 Fs   #B*.B%AB*c              #   2  #    [         R                  " 5       n[        S5       H  nUR                  [	        SS95        M     [
        R                  " UR                  5       5      nU R                  S[        UR                  5      5        [        R                  " S5      v   U R                  S[        UR                  5      5        U R                  UR                  5       5        UR                  5         U R                  UR                  5       5        g 7f)Ne   r6   rT   f   rV   r>   )r   r,   rI   r'   r   rs   rt   rA   len_waitersr   rX   rY   rm   r8   ru   )r   r2   r   r   s       r   test_garbage_collection%ConditionTest.test_garbage_collection   s      OOsAFF9T*+  &&qvvx0c!**o. iioC

O, 	'	
&s   DD)r   )__name__
__module____qualname____firstlineno__r   r!   r)   r3   r   r9   rB   rM   rQ   r[   r^   rb   re   rx   r   __static_attributes____classcell__)r   s   @r   r
   r
      s    
+*  

Q7"
H ' '   = =. : : 8 8 ' 'r   r
   c                   <    \ rS rSrS rS r\S 5       rS rS r	Sr
g)		EventTest   c                 6   [         R                  " 5       nU R                  S[        U5      ;   5        U R	                  S[        U5      ;   5        UR                  5         U R	                  S[        U5      ;   5        U R                  S[        U5      ;   5        g )Nclearset)r   Eventru   strrY   r   )r   events     r   r3   EventTest.test_repr   sn    3u:-.#e*,-		CJ./U+,r   c                     [         R                  " 5       n[        R                  " UR	                  5       5      nUR                  5         [        R                  " UR	                  5       5      nUR                  5         [        R                  " UR	                  5       5      nU R                  UR                  5       5        U R                  UR                  5       5        U R                  UR                  5       5        g r   )
r   r   rs   rt   r'   r   r   ru   rm   rY   )r   efuture_0future_1future_2s        r   
test_eventEventTest.test_event   s    KKM((2	((2		((2(()r   c              #   V  #    [         R                  " 5       nU R                  [        5         UR	                  [        SS95      v   S S S 5        U R                  R                  [        SS9UR                  5        UR	                  [        SS95      v   g ! , (       d  f       NV= f7f)Nr6   rT   r>   )	r   r   assertRaisesr   r'   r   r$   add_timeoutr   r   r   s     r   test_event_timeoutEventTest.test_event_timeout   sr     KKM|,&&4011 - 	  4!8!%%@ffYq)** -,s   +B)BAB)
B&"B)c                     [         R                  " 5       nUR                  5         UR                  5         U R                  UR	                  5       5        g r   )r   r   r   ru   is_setr   s     r   test_event_set_multiple!EventTest.test_event_set_multiple   s1    KKM		
#r   c                 z   [         R                  " 5       n[        R                  " UR	                  5       5      nUR                  5         [        R                  " UR	                  5       5      nUR                  5         U R                  UR                  5       5        U R                  UR                  5       5        g r   )	r   r   rs   rt   r'   r   r   ru   rm   )r   r   f0f1s       r   test_event_wait_clearEventTest.test_event_wait_clear   so    KKM""1668,		""1668,		"	"r    N)r   r   r   r   r3   r   r   r   r   r   r   r   r   r   r   r      s*    -
* + +$#r   r   c                   \    \ rS rSrS rS rS r\S 5       r\S 5       r	S r
\S 5       rS	rg
)SemaphoreTest   c                 J    U R                  [        [        R                  SS9  g )Nvalue)r   
ValueErrorr   	Semaphorer(   s    r   test_negative_value!SemaphoreTest.test_negative_value   s    *eooR@r   c                 |   [         R                  " 5       nU R                  S[        U5      5        U R                  S[        U5      5        UR	                  5         U R                  S[        U5      5        U R                  S[        U5      5        UR	                  5         U R                  S[        U5      5        g )Nr   zunlocked,value:1lockedr-   )r   r   r.   r/   acquirer0   r   sems     r   r3   SemaphoreTest.test_repr   s}    ook49-($s)4hS	*DI.ic+r   c                 h   [         R                  " 5       n[        R                  " UR	                  5       5      nU R                  UR                  5       5        [        R                  " UR	                  5       5      nU R                  UR                  5       5        [        R                  " UR	                  5       5      nUR                  5         U R                  UR                  5       5        U R                  UR                  5       5        UR                  5         U R                  UR                  5       5        UR                  5         U R                  [        R                  " UR	                  5       5      R                  5       5        U R                  S[        UR                  5      5        g )Nr   )r   r   rs   rt   r   ru   rm   rY   releaserA   r}   r~   )r   r   r   r   f2s        r   test_acquireSemaphoreTest.test_acquire  s
   oo""3;;=1	" ""3;;=1#""3;;=1	"#	"--ckkm<AACDC-.r   c              #     #    [         R                  " S5      nUR                  5       v   UR                  5       v   UR                  [        SS95      nU R                  R                  SUR                  5        [        R                  " S5      v   U R                  [        R                  5         Uv   S S S 5        UR                  5         [        R                  " UR                  5       5      nU R                  UR                  5       5        UR                  5         U R                  UR                  5       5        g ! , (       d  f       N= f7f)NrH   r6   rT   rV   g333333?)r   r   r   r   r$   r7   r   r   rX   r   r   rs   rt   rY   rm   ru   )r   r   r   ro   s       r   test_acquire_timeout"SemaphoreTest.test_acquire_timeout  s     ooa kkmkkm++i56ckk2iins//0M 1 	!!#++-0"! 10s   B0E2E7BE
EEc              #     #    [         R                  " S5      nUR                  5       v   U R                  R	                  SUR
                  5        UR                  [        SS95      n[        R                  " S5      v   Uv   g 7f)Nr>   r6   rV   rT   rW   )	r   r   r   r$   r7   r   r   r   rX   )r   r   r   s      r   test_acquire_timeout_preempted,SemaphoreTest.test_acquire_timeout_preempted'  s_     ooa kkm 	ckk2++i56iios   BBc                 v   [         R                  " 5       nUR                  5         UR                  5         U R                  [        R
                  " UR                  5       5      R                  5       5        U R                  [        R
                  " UR                  5       5      R                  5       5        U R                  [        R
                  " UR                  5       5      R                  5       5        U R                  [        R
                  " UR                  5       5      R                  5       5        g r   )	r   r   r   ru   rs   rt   r   rm   rY   r   s     r   test_release_unacquired%SemaphoreTest.test_release_unacquired2  s    oo 	--ckkm<AACD--ckkm<AACD--ckkm<AACD..s{{}=BBDEr   c              #     #    [         R                  " SS9n[        S5       Vs/ s H/  n[        R                  " UR                  [        SS95      5      PM1     nn[        R                  " UR                  5       5      nU R                  S[        UR                  5      5        [        R                  " S5      v   U R                  S[        UR                  5      5        U R                  UR                  5       5        UR                  5         U R                  UR                  5       5        U H#  nU R!                  ["        UR$                  5        M%     g s  snf 7f)	Nr   r   r{   r6   rT   r|   rV   r>   )r   r   rI   rs   rt   r   r   rA   r}   r~   r   rX   rY   rm   r   ru   r   r   r   )r   r   r   rw   r   s        r   r   %SemaphoreTest.test_garbage_collection>  s     ooA& 3Z
 !!#++i.E"FG 	 

 &&s{{}5c#,,/0 iioC-. 	'& FlFMM: %
s   "E6EDEr   N)r   r   r   r   r   r3   r   r   r   r   r   r   r   r   r   r   r   r      sT    A,/( " "   
F ; ;r   r   c                       \ rS rSr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	 rS
rg)SemaphoreContextManagerTestiX  c              #   6  #    [         R                  " 5       nUR                  5       v  nU R                  US L 5        S S S 5        U R                  [        R
                  " UR                  5       5      R                  5       5        g ! , (       d  f       NP= f7fr   )r   r   r   ru   rs   rt   rm   )r   r   yieldeds      r   test_context_manager0SemaphoreContextManagerTest.test_context_managerY  sd     ooKKM!gOOGtO, " 	--ckkm<AACD	 "!s   (BBA
B
BBc              #      ^ ^#    [         R                  " 5       mU U4S jnU" 5       v   T R                  [        R                  " TR                  5       5      R                  5       5        g 7f)Nc                     >#    T IS h  vN n TR                  U S L 5        S S S 5      IS h  vN   g  N( N! , IS h  vN  (       d  f       g = f7fr   )ru   )r   r   r   s    r   ro   GSemaphoreContextManagerTest.test_context_manager_async_await.<locals>.fg  s,     sg40 ssssss:   A3A7A5AAAA A
A)r   r   ru   rs   rt   r   rm   )r   ro   r   s   ` @r    test_context_manager_async_await<SemaphoreContextManagerTest.test_context_manager_async_awaitb  sJ      oo	1 c	 	--ckkm<AACDs   A(A,c              #   x  #    [         R                  " 5       nU R                  [        5         UR	                  5       v    SS-    S S S 5        S S S 5        U R                  [        R                  " UR	                  5       5      R                  5       5        g ! , (       d  f       NX= f! , (       d  f       Na= f7f)Nr>   r   )	r   r   r   ZeroDivisionErrorr   ru   rs   rt   rm   r   s     r   test_context_manager_exception:SemaphoreContextManagerTest.test_context_manager_exceptionp  sv     oo01%A & 2
 	--ckkm<AACD	 &% 21s5   +B:B) BB)A
B:
B&	"B))
B73B:c              #   "  #    [         R                  " 5       nUR                  [        SS95      v     S S S 5        U R	                  [
        R                  " UR                  5       5      R                  5       5        g ! , (       d  f       NP= f7f)Nr6   rT   )r   r   r   r   ru   rs   rt   rm   r   s     r   test_context_manager_timeout8SemaphoreContextManagerTest.test_context_manager_timeoutz  s]     ooKK	$ 788 9 	--ckkm<AACD	 98s   0BA>A
B>
BBc              #     #    [         R                  " SS9nU R                  [        R                  5         UR                  [        SS95      v     S S S 5        S S S 5        U R                  [        R                  " UR                  5       5      R                  5       5        g ! , (       d  f       NX= f! , (       d  f       Na= f7f)Nr   r   r6   rT   )r   r   r   r   r   r   r   rY   rs   rt   rm   r   s     r   "test_context_manager_timeout_error>SemaphoreContextManagerTest.test_context_manager_timeout_error  s     ooA&s//0Id$;<< = 1
 	..s{{}=BBDE	 =< 10s5   4CB6B%B6A
C%
B3	/B66
C Cc              #   @  ^^#    [         R                  " 5       m/ m[        R                  UU4S j5       n[	        S5       Vs/ s H
  o!" U5      PM     snv   / n[	        S5       H  nUR                  SU-  SU-  /5        M     U R                  UT5        g s  snf 7f)Nc              3      >#    TR                  5       v    TR                  SU -  5        [        R                  " S5      v   TR                  SU -  5        S S S 5        g ! , (       d  f       g = f7f)Nacquired %dr6   
release %d)r   r   r   rX   )indexr   r   s    r   ro   ESemaphoreContextManagerTest.test_context_manager_contended.<locals>.f  sM     %}u45iio%|e34 &%%s   A1AA 	A1 
A.*A1rH   r   r   )r   r   r   	coroutinerI   extendrA   )r   ro   rL   expected_historyr   r   s       @@r   test_context_manager_contended:SemaphoreContextManagerTest.test_context_manager_contended  s     oo		5 
	5 #1X&XqtX&&qA##]Q%6q8H$IJ  	)73 's   ?BBA
Bc              #      #    U R                  [        R                  5         [        R                  " 5       v     S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7fr   )r   r   BadYieldErrorr   r   r(   s    r   test_yield_sem*SemaphoreContextManagerTest.test_yield_sem  sG      s001)) * 21)) 212    A/AAA	A/
A	A
A,(A/c                     U R                  [        5         [        R                  " 5           S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fr   )r   RuntimeErrorr   r   r(   s    r   test_context_manager_misuse7SemaphoreContextManagerTest.test_context_manager_misuse  s<     |," # -,"" -,   A?A
A		A
Ar   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   X  s    E E E E E E E E F F 4 4&  r   r   c                       \ rS rSrS rSrg)BoundedSemaphoreTesti  c                    [         R                  " 5       nU R                  [        UR                  5        UR                  5         [        R                  " UR                  5       5      nU R                  UR                  5       5        UR	                  5         U R                  UR                  5       5        UR	                  5         U R                  [        UR                  5        g r   )r   BoundedSemaphorer   r   r   r   rs   rt   rY   rm   ru   )r   r   r   s      r   r   ,BoundedSemaphoreTest.test_release_unacquired  s    $$&*ckk2&&s{{}5'&*ckk2r   r   N)r   r   r   r   r   r   r   r   r   r   r     s    3r   r   c                   l    \ rS rSrS rS r\S 5       r\S 5       r\S 5       r	S r
\S 5       rS	 rS
rg)	LockTestsi  c                 z    [         R                  " 5       n[        U5        UR                  5         [        U5        g r   )r   Lockr/   r   r   locks     r   r3   LockTests.test_repr  s$    zz|T
T
r   c                    [         R                  " 5       nU R                  [        R                  " UR                  5       5      R                  5       5        [        R                  " UR                  5       5      nU R                  UR                  5       5        UR                  5         U R                  UR                  5       5        g r   )	r   r   ru   rs   rt   r   rm   rY   r   )r   r   r   s      r   test_acquire_releaseLockTests.test_acquire_release  sx    zz|--dlln=BBDE&&t||~6'&r   c              #     ^^#    [         R                  " 5       mU R                  [        R                  " TR                  5       5      R                  5       5        Sn/ m[        R                  UU4S j5       n[        U5       Vs/ s H
  o2" U5      PM     nnU R                  [        S U 5       5      5        TR                  5         Uv   U R                  [        [        U5      5      T5        g s  snf 7f)N   c              3      >#    TR                  5       v    TR                  U 5        S S S 5        g ! , (       d  f       g = f7fr   )r   r   idxr   r   s    r   ro   &LockTests.test_acquire_fifo.<locals>.f  s)     &s# '&&s   A1	A
?Ac              3   @   #    U  H  oR                  5       v   M     g 7fr   rl   )rn   r   s     r   rp   .LockTests.test_acquire_fifo.<locals>.<genexpr>  s     Av[[]]rr   )r   r   ru   rs   rt   r   rm   r   r   rI   rY   anyr   rA   rJ   r   Nro   rL   rw   r   r   s        @@r   test_acquire_fifoLockTests.test_acquire_fifo  s     zz|--dlln=BBDE		$ 
	$ "'q*A1Q4*AAABeAh1	 +s   BC8C3A!C8c              #     ^^#    [         R                  " 5       mU R                  [        R                  " TR                  5       5      R                  5       5        Sn/ mUU4S jn[        U5       Vs/ s H
  o2" U5      PM     nnTR                  5         Uv   U R                  [        [        U5      5      T5        g s  snf 7f)Nr  c                    >#    T IS h  vN   TR                  U 5        S S S 5      IS h  vN   g  N& N! , IS h  vN  (       d  f       g = f7fr   )r   r  s    r   ro   1LockTests.test_acquire_fifo_async_with.<locals>.f  s&     ts# ttttts9   A1A5A3AAA>AA)r   r   ru   rs   rt   r   rm   rI   r   rA   rJ   r  s        @@r   test_acquire_fifo_async_with&LockTests.test_acquire_fifo_async_with  s      zz|--dlln=BBDE	$ "'q*A1Q4*eAh1 +s   A/C3B?A Cc              #   z  #    [         R                  " 5       nUR                  5         U R                  [        R
                  5         UR                  [        SS9S9v   S S S 5        U R                  [        R                  " UR                  5       5      R                  5       5        g ! , (       d  f       NP= f7f)Nr6   rT   )r   )r   r   r   r   r   r   r   rY   rs   rt   rm   r   s     r   r   LockTests.test_acquire_timeout  sz     zz|s//0,,y'>,?? 1 	..t||~>CCEF	 10s   AB;B* A
B;*
B84B;c                     [         R                  " 5       nU R                  [        UR                  5        UR                  5         UR	                  5         U R                  [        UR                  5        g r   )r   r   r   r   r   r   r   s     r   test_multi_releaseLockTests.test_multi_release  sG    zz|,5,5r   c              #      #    U R                  [        R                  5         [        R                  " 5       v     S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7fr   )r   r   r   r   r   r(   s    r   test_yield_lockLockTests.test_yield_lock  sF      s001

$ % 21$$ 21r   c                     U R                  [        5         [        R                  " 5           S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fr   )r   r   r   r   r(   s    r   r   %LockTests.test_context_manager_misuse  s:     |,  -, -,r   r   N)r   r   r   r   r3   r   r   r  r  r   r  r  r   r   r   r   r   r   r     sh    ' 2 2" 2 2" G G6  r   r   __main__)rs   datetimer   typingunittesttornador   r   tornado.genr   tornado.testingr   r   r
   r   r   r   r   r   r   mainr   r   r   <module>r&     s         $ 3k'M k'\,# ,#^a;M a;HV- Vr3= 3 R Rj zMMO r   