
    i                         d dl mZ d dlZd dlZd dlmZ  G d dej                  Zedk    r ej	                     dS dS )    )contextmanagerN)ignores_leakcheckc                   l    e Zd Zd Zed             Zed             Zed             Z	ed             Z
dS )TestJoinc                    t          j                                                    }|                     |           |                     t          j                    j                   t          j                                                    }|                     |           t          j        d           t          j                                                    }|                     |           d S )Ng{Gz?)geventget_hubjoin
assertTrueassertFalsedeadsleep)selfress     F/usr/local/lib/python3.11/dist-packages/gevent/tests/test__hub_join.pytest_join_many_timeszTestJoin.test_join_many_times
   s    n##%%)).///n##%% 	Tn##%%    c                      dd l } t          d          D ]+}|                                 r	 |                                 ,d S )Nr      )gcrangecollect)r   _s     r   __cleanzTestJoin.__clean   sP    			q 	 	A**,,  **,, 	 	r   c              #      K   ddl m} | j        } |             t           |                      }d V  t           |                      }||k    r|dz  }|                     ||           d S )Nr   )get_reachable_greenlets   )gevent._greenlet_primitivesr   _TestJoin__cleanlenassertEqual)r   r   cleancount_beforecount_afters        r   assert_no_greenlet_growthz"TestJoin.assert_no_greenlet_growth    s      GGGGGG224455113344%% 1K 	l33333r   c                     dd l | j        d }fd}|                                 5  t          d          D ]} ||           ~~d d d            d S # 1 swxY w Y   d S )Nr   c                      t          j        d           } |                                  |                                  t          j                    }|                                 |                    d           ~d S )Nc                      dS Nr    r*   r   r   <lambda>zcTestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet.<locals>.thread_main.<locals>.<lambda>9   s    A r   runTdestroy_loop)r   Greenletstartr
   r	   destroy)ghubs     r   thread_mainzQTestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet.<locals>.thread_main8   se    II...AGGIIIFFHHH.""CHHJJJKKTK***r   c                                          |           }|                                 |                                               d S )N)target)Threadr1   r
   )maintr"   	threadings     r   testerzLTestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet.<locals>.testerA   sB       --AGGIIIFFHHHEGGGGGr   
   )r;   r   r%   r   )r   r5   r<   r   r"   r;   s       @@r   3test_join_in_new_thread_doesnt_leak_hub_or_greenletz<TestJoin.test_join_in_new_thread_doesnt_leak_hub_or_greenlet2   s     		 	 		 	 	 	 	 	 ++-- 	 	2YY $ ${####	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    AAAc                     dd l }| j        } G d d|j                  }d }t          d          D ]} |||           ~~d S )Nr   c                       e Zd ZdZd ZdS )DTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.ThreadNc                     t          j        d           }|                                 |                                 ~t          j                    }|                                 || _        d S )Nc                      dS r)   r*   r*   r   r   r+   zZTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.Thread.run.<locals>.<lambda>X   s     r   r,   )r   r0   r1   r
   r	   r4   )r   r3   r4   s      r   r-   zHTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.Thread.runW   sX    O		222			n&&


r   )__name__
__module____qualname__r4   r-   r*   r   r   r8   rA   U   s(        C    r   r8   c                      |             }|                                  |                                 |j                            d           d |_        ~ |             d S )NTr.   )r1   r
   r4   r2   )r8   r"   r:   s      r   r<   zDTestJoin.test_destroy_in_main_thread_from_new_thread.<locals>.tester`   sV    AGGIIIFFHHHEMMtM,,,AEEGGGGGr   r=   )r;   r   r8   r   )r   r;   r"   r8   r<   r   s         r   +test_destroy_in_main_thread_from_new_threadz4TestJoin.test_destroy_in_main_thread_from_new_threadO   s     			 		 		 		 		Y% 		 		 			 	 	 r 	" 	"AF65!!!!FFr   N)rD   rE   rF   r   staticmethodr   r   r%   r   r>   rH   r*   r   r   r   r      s             \ 4 4 ^4"   8 ! ! ! ! !r   r   __main__)

contextlibr   unittestr   gevent.testingr   TestCaser   rD   r9   r*   r   r   <module>rO      s    % % % % % %   , , , , , ,i i i i ix  i i iX zHMOOOOO r   