
    <|h10                        d dl mZ  ej                          d dl mZ d dlZd dlZd dlZdZ G d dej                        Z
 G d de      Z G d	 d
ej                  e      Z G d de      Z G d de      Z G d de      Z G d dej                        Z G d dej                  e      Zedk(  r ej,                          yy)    )monkey)queueN   c                       e Zd Zd Zd Zy)_TriggerThreadc                     || _         || _        ddlm}  |       | _        t
        j                  j                  |        y )Nr   )Event)fnargsgevent.eventr	   startedEvent	threadingThread__init__)selfr
   r   r	   s       ^/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/tests/test__monkey_queue.pyr   z_TriggerThread.__init__   s1    	&!G!!$'    c                     t        j                  d       | j                  j                           | j                  | j
                    y )N{Gz?)timesleepr   setr
   r   r   s    r   runz_TriggerThread.run   s4     	

4r   N)__name__
__module____qualname__r   r    r   r   r   r      s    (r   r   c                       e Zd Zd Zd Zy)BlockingTestMixinc                    t        ||      | _        | j                  j                           || | _        | j                  j                  j                         s| j                  d|z         | j                  j                  d       | j                  j                         r| j                  d|z         | j                  S )Nz,blocking function '%r' appeared not to block
   ,trigger function '%r' appeared to not return)	r   tstartresultr   isSetfailjoinis_alive)r   
block_func
block_argstrigger_functrigger_argss        r   do_blocking_testz"BlockingTestMixin.do_blocking_test3   s    l; *-vv""((*IID ! "B66??IID"# ${{r   c                    t        ||      | _        | j                  j                          	 | j                  |      5   ||  d d d        | j                  j	                  d       | j                  j                         r| j                  d|z         | j                  j                  j                         s| j                  d       y y # 1 sw Y   xY w# | j                  j	                  d       | j                  j                         r| j                  d|z         | j                  j                  j                         s| j                  d       w w xY w)Nr"   r#   z(trigger thread ended but event never set)	r   r$   r%   assertRaisesr)   r*   r(   r   r'   )r   r+   r,   r-   r.   expected_exception_classs         r   do_exceptional_blocking_testz.BlockingTestMixin.do_exceptional_blocking_testB   s   l;		F""#;< (J'( FFKKOvv 		H&' (66&&,,.		DE /( ( FFKKOvv 		H&' (66&&,,.		DE /s#   C CC CC BEN)r   r   r   r/   r3   r   r   r   r    r    1   s    Fr   r    c                   T    e Zd Zej                  Zd Zd Zd Zd Zd Z	d Z
d Zd Zy	)
BaseQueueTestc                 D    d| _         t        j                         | _        y )Nr   )cumr   Lockcumlockr   s    r   setUpzBaseQueueTest.setUpU   s     ~~'r   c                    |j                         st        d      |j                  d       |j                  d       |j                  d       |j                  d       t        ddd      }|j	                         |j                         f}| j                  |||j                  j                     ||j                  j                     fd       t        g dg d	g d
      }|j                         |j                         |j                         g}| j                  |||j                  j                     d       t        t        dz
        D ]3  }|j                  |       | j                  |j                         d       5 | j                  |j                         d       |j                  d       | j                  |j                         d       	 |j                  dd       | j                  d       	 |j                  dd       | j                  d       | j                  |j#                         t               | j%                  |j                  d|j
                  d       | j%                  |j                  d|j
                  d       t        t              D ]  }|j                           | j                  |j                         d       	 |j                  d       | j                  d       	 |j                  d       | j                  d       | j%                  |j
                  d|j                  d       | j%                  |j
                  d|j                  d       y # t        j                   $ r Y w xY w# t        j                   $ r Y w xY w# t        j&                  $ r Y w xY w# t        j&                  $ r Y w xY w) N&Call this function with an empty queueo   M       )Queue	LifoQueuePriorityQueuez#q.peek() and q.get() are not equal!)r>   r?   r@   )r?   r>   r=   )r?   r>   r@   z&Didn't seem to queue the correct data!   Queue should not be emptyQueue should not be full  Queue should be fullx  r   blockz(Didn't appear to block with a full queuer   timeoutz+Didn't appear to time-out with a full queuerI   r   rI   Tr"   Queue should be emptyz*Didn't appear to block with an empty queuez-Didn't appear to time-out with an empty queueempty)Tr"   )rR   RuntimeErrorputdictpeekgetassertEqual	__class__r   range
QUEUE_SIZEassertFalsefull
assertTruer(   rA   Fullqsizer/   Empty)r   qtarget_first_itemsactual_first_itemtarget_orderactual_orderis          r   simple_queue_testzBaseQueueTest.simple_queue_testY   s   wwyGHH	c
	c
	c
	c
! VVXquuw/*,Q[[-A-AB,Q[[-A-ABD>	@ /&5*9; !%%'2|AKK4H4H'IA	Cz!|$ 	EAEE!HQWWY(CD	E 	#=>	c
"89	EE#QEII@A	EE#tE$IICD 	J/aeeVQUUB7aee_aeeR@z" 	AEEG		#:;	EEENIIBC	EE$EIIEF 	aeeR
;aeeZ
C7 zz 		
 zz 		 {{ 		
 {{ 		sH   $M2 =$N #N& >#N? 2N	N	N#"N#&N<;N<?OOc                     	 |j                         }||j                          y | xj                  |z  c_        |j                          IN)rW   	task_doner7   )r   rb   xs      r   workerzBaseQueueTest.worker   s<    AyHHMHKKM r   c                    d| _         dD ]2  }t        j                  | j                  |f      j	                          4 t        d      D ]  }|j                  |        |j                          | j                  | j                   t        t        d            d       dD ]  }|j                  d         |j                          y )Nr   )r   rD   )targetr   d   z0q.join() did not block until all tasks were done)
r7   r   r   rm   r%   rZ   rT   r)   rX   sumr   rb   rg   s      r   queue_join_testzBaseQueueTest.queue_join_test   s     	DADKKqd;AAC	Ds 	AEE!H		3uSz?K	M 	AEE$K		r   c                     t        j                         }	 |j                          | j                  d       y # t        $ r Y y w xY wN(Did not detect task count going negative)rA   JoinableQueuerk   r(   
ValueErrorr   rb   s     r   test_queue_task_donez"BaseQueueTest.test_queue_task_done   sB    !	BKKM II@A  		s   8 	AAc                     t        j                         }| j                  |       | j                  |       	 |j                          | j	                  d       y # t
        $ r Y y w xY wru   )rA   rw   rs   rk   r(   rx   ry   s     r   test_queue_joinzBaseQueueTest.test_queue_join   s`     !QQ	BKKM II@A  		s   A 	A&%A&c                    g d}t        j                  |      }|D ]S  }| j                  |j                  d             | j	                  ||j                                |j                          U 	 |j                          | j                  d       | j                  |j                  d             y # t        $ r Y -w xY w)N)rD         itemsgMbP?rL   rv   )
rA   rw   r\   r)   rX   rW   rk   r(   rx   r^   )r   lrb   rg   s       r   test_queue_task_done_with_itemsz-BaseQueueTest.test_queue_task_done_with_items   s    
 a( 	AQVVEV23Q(KKM	
	BKKM II@Au-.	  		s   4B7 7	CCc                 r    | j                  t              }| j                  |       | j                  |       y rj   )	type2testr[   rh   ry   s     r   test_simple_queuezBaseQueueTest.test_simple_queue   s.     NN:&q!q!r   N)r   r   r   rA   r   r:   rh   rm   rs   rz   r|   r   r   r   r   r   r5   r5   R   s7    I(;Dz	BB/("r   r5   c                   $    e Zd Zej                  Zy)LifoQueueTestN)r   r   r   rA   rB   r   r   r   r   r   r      s    Ir   r   c                   *    e Zd Zej                  Zd Zy)PriorityQueueTestc                     d}d}| j                  ||g      }| j                  ||j                                | j                  ||j                                y )N)r~   b)rD   ar   )r   assertTupleEqual
get_nowait)r   item1item2rb   s       r   
test__initzPriorityQueueTest.test__init   sL    NN%N0eQ\\^4eQ\\^4r   N)r   r   r   rA   rC   r   r   r   r   r   r   r      s    ##I5r   r   c                       e Zd Zy)FailingQueueExceptionN)r   r   r   r   r   r   r   r      s    r   r   c                       e Zd Zd Zd Zd Zy)FailingQueuec                 `    d| _         d| _        t        j                  j                  | g|  y )NF)fail_next_putfail_next_getrA   r   )r   r   s     r   r   zFailingQueue.__init__   s)    ""T)D)r   c                 ~    | j                   rd| _         t        d      t        j                  j                  | |      S NFzYou Lose)r   r   rA   _put)r   items     r   r   zFailingQueue._put   s5    !&D'
33{{d++r   c                 |    | j                   rd| _         t        d      t        j                  j                  |       S r   )r   r   rA   _getr   s    r   r   zFailingQueue._get   s3    !&D'
33{{%%r   N)r   r   r   r   r   r   r   r   r   r   r      s    *,
&r   r   c                       e Zd Zd Zd Zy)FailingQueueTestc                 P   |j                         st        d      t        t        dz
        D ]  }|j	                  |        d|_        | j                  t              5  |j	                  dd       d d d        d|_        | j                  t              5  |j	                  dd       d d d        |j	                  d	       | j                  |j                         d
       d|_        | j                  t              5  | j                  |j                  d|j                  d       d d d        |j	                  d	       d|_        | j                  |j                  d|j                  dt               |j	                  d	       | j                  |j                         d
       |j                          | j                  |j                         d       |j	                  d	       | j                  |j                         d
       | j                  |j                  d|j                  d       t        t              D ]  }|j                           | j                  |j                         d       |j	                  d       d|_        | j                  t              5  |j                          d d d        | j                  |j                         d       d|_        | j                  t              5  |j                  d       d d d        | j                  |j                         d       |j                          | j                  |j                         d       d|_        | j                  |j                  d|j                  dt               | j                  |j                         d       |j                          | j                  |j                         d       y # 1 sw Y   uxY w# 1 sw Y   JxY w# 1 sw Y   xY w# 1 sw Y   ]xY w# 1 sw Y   xY w)Nr<   rD   Toopsr   rJ   g?rL   rG   rH   rN   r   rO   rF   rP   firstrE   rQ   )rR   rS   rZ   r[   rT   r   r1   r   r^   r]   r/   rW   r3   r\   r   rr   s      r   failing_queue_testz#FailingQueueTest.failing_queue_test  s(   wwyGHHz!|$ 	AEE!H	 45 	#EE&E"	# 45 	'EE&#E&	'	c
"8945 	<!!!%%;	<
 	
c
))!%%!%%*?	A 	
c
"89	#=>	c
"89aeeVQUUB7z" 	AEEG		#:;	g45 	EEG	 	$?@45 	EE#E	$?@		#:;))!%%QUUJ*?	A 	$?@		#:;i	# 	#	' 	'	< 	<4	 	
	 	s<    O'O4)P"P7P'O14O>PPP%c                 f    t        t              }| j                  |       | j                  |       y rj   )r   r[   r   ry   s     r   test_failing_queuez#FailingQueueTest.test_failing_queueB  s*     $""r   N)r   r   r   r   r   r   r   r   r   r     s    ;<z#r   r   __main__)geventr   	patch_allr   rA   r   r   unittestr[   r   r   objectr    TestCaser5   r   r   	Exceptionr   r   r   r   mainr   r   r   <module>r      s         !    
Y%% DF FBM"H%%'8 M"^ M  5 5	I 	&5;; & D#x((*; D#N zHMMO r   