B
    u9al«  ã               @   sê  d dl Zej d¡ ej d¡ 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Zd dlZd dlZd dl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mZmZmZmZmZmZ d d	lmZ d d
l m!Z! eddfdd„Z"e"edZ#e"edZ$e"edZ%e"edZ&e"ee'ƒ dZ(e"eddZ)da*dd„ Z+dd„ Z,dd„ Z-dd„ Z.dd„ Z/dd„ Z0dhdd„Z1G d d!„ d!e2ƒZ3G d"d#„ d#ƒZ4d$d%„ Z5G d&d'„ d'ej6ƒZ7G d(d)„ d)ƒZ8G d*d+„ d+e8ƒZ9G d,d-„ d-e8ƒZ:G d.d/„ d/e8ƒZ;G d0d1„ d1e8ƒZ<e7fe9e:e<e;ffd2d3„Z=G d4d5„ d5e8ƒZ>G d6d7„ d7e8ƒZ?e=e>ƒ e=e?ƒ G d8d9„ d9ƒZ@G d:d;„ d;e9e@e7ƒZAG d<d=„ d=e@ƒZBe=eBe:e<e;fd> G d?d@„ d@ƒZCG dAdB„ dBe9eCe7ƒZDe=eCe:e<e;fd> G dCdD„ dDƒZEe=eEƒ G dEdF„ dFƒZFG dGdH„ dHe9eFe7ƒZGG dIdJ„ dJeFƒZHe=eHe:e<e;fd> dKdL„ ZIdidMdN„ZJdOdP„ ZKdQdR„ ZLdSdT„ ZMG dUdV„ dVe2ƒZNG dWdX„ dXe2ƒZOG dYdZ„ dZe2ƒZPG d[d\„ d\e2ƒZQG d]d^„ d^e2ƒZRG d_d`„ d`e2ƒZSG dadb„ dbƒZTe=eTe:e<e;fd> G dcdd„ dde7ƒZUejjVdedf„ ƒZWeXdgkræeWƒ  dS )jé    NZ_multiprocessingzmultiprocessing.synchronize)Úassert_python_ok)ÚQueueHandler)ÚPicklingError)Úfutures)ÚPENDINGÚRUNNINGÚ	CANCELLEDÚCANCELLED_AND_NOTIFIEDÚFINISHEDÚFutureÚBrokenExecutor)ÚBrokenProcessPool)Úget_contextc             C   s   t ƒ }| |_||_||_|S )N)r   Ú_stateÚ
_exceptionZ_result)ÚstateÚ	exceptionÚresultÚf© r   ú-/usr/lib/python3.7/test_concurrent_futures.pyÚcreate_future   s
    r   )r   )r   r   é*   )r   r   Úuninitializedc             C   s   | | S )Nr   )ÚxÚyr   r   r   Úmul1   s    r   c              O   s   | |fS )Nr   )ÚargsÚkwargsr   r   r   Úcapture4   s    r   c             C   s   t  | ¡ tdƒ‚d S )Nzthis is an exception)ÚtimeÚsleepÚ	Exception)Útr   r   r   Úsleep_and_raise7   s    
r$   c             C   s    t  | ¡ t|ƒ tj ¡  d S )N)r    r!   ÚprintÚsysÚstdoutÚflush)r#   Úmsgr   r   r   Úsleep_and_print;   s    
r*   c             C   s   | a d S )N)ÚINITIALIZER_STATUS)r   r   r   r   Úinit@   s    r,   c               C   s   t S )N)r+   r   r   r   r   Úget_init_statusD   s    r-   c             C   sF   | d k	r0t  d¡}| t| ƒ¡ | d¡ d|_t d¡ tdƒ‚d S )Nzconcurrent.futuresÚCRITICALFgš™™™™™¹?zerror in initializer)	ÚloggingZ	getLoggerZ
addHandlerr   ZsetLevelZ	propagater    r!   Ú
ValueError)Ú	log_queueZloggerr   r   r   Ú	init_failG   s    


r2   c               @   s   e Zd Zdd„ ZdS )ÚMyObjectc             C   s   d S )Nr   )Úselfr   r   r   Ú	my_methodR   s    zMyObject.my_methodN)Ú__name__Ú
__module__Ú__qualname__r5   r   r   r   r   r3   Q   s   r3   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚEventfulGCObjc             C   s   t |ƒ ¡ }| ¡ | _d S )N)r   ZManagerÚEventÚevent)r4   ÚctxZmgrr   r   r   Ú__init__W   s    zEventfulGCObj.__init__c             C   s   | j  ¡  d S )N)r;   Úset)r4   r   r   r   Ú__del__[   s    zEventfulGCObj.__del__N)r6   r7   r8   r=   r?   r   r   r   r   r9   V   s   r9   c             C   s   t ƒ S )N)r3   )Ú_r   r   r   Úmake_dummy_object_   s    rA   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseTestCasec             C   s   t j ¡ | _d S )N)ÚtestÚsupportZthreading_setupÚ_thread_key)r4   r   r   r   ÚsetUpd   s    zBaseTestCase.setUpc             C   s   t j ¡  t jj| jŽ  d S )N)rC   rD   Úreap_childrenZthreading_cleanuprE   )r4   r   r   r   ÚtearDowng   s    
zBaseTestCase.tearDownN)r6   r7   r8   rF   rH   r   r   r   r   rB   c   s   rB   c                   s@   e Zd ZdZi Z‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Z‡  Z	S )
ÚExecutorMixiné   c                sf   t ƒ  ¡  t ¡ | _t| dƒr@| jf | j|  ¡ dœ| j	—Ž| _
n| jf d| ji| j	—Ž| _
|  ¡  d S )Nr<   )Úmax_workersÚ
mp_contextrK   )ÚsuperrF   r    Ú	monotonicÚt1ÚhasattrÚexecutor_typeÚworker_countr   Úexecutor_kwargsÚexecutorÚ_prime_executor)r4   )Ú	__class__r   r   rF   p   s    



zExecutorMixin.setUpc                sV   | j jdd d | _ t ¡ | j }tjjr:td| dd |  	|dd¡ t
ƒ  ¡  d S )NT)Úwaitz%.2fsú )Úendi,  z+synchronization issue: test lasted too long)rT   Úshutdownr    rN   rO   rC   rD   Úverboser%   Z
assertLessrM   rH   )r4   Zdt)rV   r   r   rH      s    zExecutorMixin.tearDownc             C   s
   t | jƒS )N)r   r<   )r4   r   r   r   r   Š   s    zExecutorMixin.get_contextc                s2   ‡ fdd„t ˆ jƒD ƒ}x|D ]}| ¡  qW d S )Nc                s   g | ]}ˆ j  tjd ¡‘qS )gš™™™™™¹?)rT   Úsubmitr    r!   )Ú.0r@   )r4   r   r   ú
<listcomp>   s   z1ExecutorMixin._prime_executor.<locals>.<listcomp>)ÚrangerR   r   )r4   r   r   r   )r4   r   rU      s    

zExecutorMixin._prime_executor)
r6   r7   r8   rR   rS   rF   rH   r   rU   Ú__classcell__r   r   )rV   r   rI   l   s   rI   c               @   s   e Zd ZejZdS )ÚThreadPoolMixinN)r6   r7   r8   r   ÚThreadPoolExecutorrQ   r   r   r   r   ra   –   s   ra   c                   s&   e Zd ZejZdZ‡ fdd„Z‡  ZS )ÚProcessPoolForkMixinÚforkc                s   t jdkr|  d¡ tƒ  ¡ S )NÚwin32zrequire unix system)r&   ÚplatformÚskipTestrM   r   )r4   )rV   r   r   r   ž   s    

z ProcessPoolForkMixin.get_context)	r6   r7   r8   r   ÚProcessPoolExecutorrQ   r<   r   r`   r   r   )rV   r   rc   š   s   rc   c               @   s   e Zd ZejZdZdS )ÚProcessPoolSpawnMixinZspawnN)r6   r7   r8   r   rh   rQ   r<   r   r   r   r   ri   ¤   s   ri   c                   s&   e Zd ZejZdZ‡ fdd„Z‡  ZS )ÚProcessPoolForkserverMixinZ
forkserverc                s   t jdkr|  d¡ tƒ  ¡ S )Nre   zrequire unix system)r&   rf   rg   rM   r   )r4   )rV   r   r   r   ­   s    

z&ProcessPoolForkserverMixin.get_context)	r6   r7   r8   r   rh   rQ   r<   r   r`   r   r   )rV   r   rj   ©   s   rj   c             C   sT   dd„ }xF|D ]>}d||j ƒ|| j ƒf }t|| f|f | i ƒ}|tƒ |< qW d S )Nc             S   s4   |   d¡r| d d… S |   d¡r,| d d… S | S d S )N)ZMixinZTestséûÿÿÿZTestéüÿÿÿ)Úendswith)Únamer   r   r   Ústrip_mixin¸   s
    

z*create_executor_tests.<locals>.strip_mixinz%s%sTest)r6   ÚtypeÚglobals)ZmixinÚbasesÚexecutor_mixinsro   Zexern   Úclsr   r   r   Úcreate_executor_tests³   s    
ru   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚInitializerMixiné   c                s    da ttdd| _tƒ  ¡  d S )Nr   )Úinitialized)ÚinitializerÚinitargs)r+   Údictr,   rS   rM   rF   )r4   )rV   r   r   rF   Ê   s    
zInitializerMixin.setUpc                s:   ‡ fdd„t ˆ jƒD ƒ}x|D ]}ˆ  | ¡ d¡ qW d S )Nc                s   g | ]}ˆ j  t¡‘qS r   )rT   r\   r-   )r]   r@   )r4   r   r   r^   Ò   s   z5InitializerMixin.test_initializer.<locals>.<listcomp>rx   )r_   rR   ÚassertEqualr   )r4   r   r   r   )r4   r   Útest_initializerÑ   s    

z!InitializerMixin.test_initializer)r6   r7   r8   rR   rF   r}   r`   r   r   )rV   r   rv   Ç   s   rv   c                   s>   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zejdd	„ ƒZ	‡  Z
S )
ÚFailingInitializerMixinrw   c                sZ   t | dƒr4|  ¡ | _| j ¡ | _tt| jfd| _nd | _d | _ttd| _tƒ  	¡  d S )Nr<   )ry   rz   )ry   )
rP   r   rL   ZQueuer1   r{   r2   rS   rM   rF   )r4   )rV   r   r   rF   Ü   s    

zFailingInitializerMixin.setUpc          
   C   sº   |   d¡¦ y| j t¡}W n tk
r0   Y n X |  t¡ | ¡  W d Q R X t ¡ }x0| jj	sˆt ¡ | dkr||  
d¡ t d¡ qZW |  t¡ | j t¡ W d Q R X W d Q R X d S )Nz ValueError: error in initializerrJ   zexecutor not broken after 5 s.g{®Gáz„?)Ú_assert_loggedrT   r\   r-   r   ÚassertRaisesr   r    rN   Z_brokenÚfailr!   )r4   ÚfuturerO   r   r   r   r}   ë   s    

z(FailingInitializerMixin.test_initializerc             C   s   d S )Nr   )r4   r   r   r   rU   ÿ   s    z'FailingInitializerMixin._prime_executorc          	   #   s’   | j d k	rLd V  g }yx| | j  ¡  ¡ ¡ qW W qp tjk
rH   Y qpX n$|  dd¡}d V  W d Q R X |j}|  t	‡ fdd„|D ƒƒ|¡ d S )Nzconcurrent.futuresr.   c             3   s   | ]}ˆ |kV  qd S )Nr   )r]   Úline)r)   r   r   ú	<genexpr>  s    z9FailingInitializerMixin._assert_logged.<locals>.<genexpr>)
r1   ÚappendZ
get_nowaitZ
getMessageÚqueueZEmptyZ
assertLogsÚoutputÚ
assertTrueÚany)r4   r)   r‡   Úcmr   )r)   r   r     s    
z&FailingInitializerMixin._assert_logged)r6   r7   r8   rR   rF   r}   rU   Ú
contextlibÚcontextmanagerr   r`   r   r   )rV   r   r~   Ù   s
   r~   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚExecutorShutdownTestc             C   s$   | j  ¡  |  t| j jtdd¡ d S )Nrw   rJ   )rT   rZ   r€   ÚRuntimeErrorr\   Úpow)r4   r   r   r   Útest_run_after_shutdown  s    
z,ExecutorShutdownTest.test_run_after_shutdownc             C   sD   t ddj| jjt| ddƒdƒ\}}}|  |¡ |  | ¡ d¡ d S )Nz-caK  if 1:
            from concurrent.futures import {executor_type}
            from time import sleep
            from test.test_concurrent_futures import sleep_and_print
            if __name__ == "__main__":
                context = '{context}'
                if context == "":
                    t = {executor_type}(5)
                else:
                    from multiprocessing import get_context
                    context = get_context(context)
                    t = {executor_type}(5, mp_context=context)
                t.submit(sleep_and_print, 1.0, "apple")
            r<   Ú )rQ   Úcontexts   apple)r   ÚformatrQ   r6   ÚgetattrÚassertFalser|   Ústrip)r4   ÚrcÚoutÚerrr   r   r   Útest_interpreter_shutdown  s
    

z.ExecutorShutdownTest.test_interpreter_shutdownc             C   sJ   t ddj| jjt| ddƒdƒ\}}}|  d| ¡ ¡ |  | ¡ d¡ d S )Nz-caÐ  if 1:
            import atexit
            @atexit.register
            def run_last():
                try:
                    t.submit(id, None)
                except RuntimeError:
                    print("runtime-error")
                    raise
            from concurrent.futures import {executor_type}
            if __name__ == "__main__":
                context = '{context}'
                if not context:
                    t = {executor_type}(5)
                else:
                    from multiprocessing import get_context
                    context = get_context(context)
                    t = {executor_type}(5, mp_context=context)
                    t.submit(id, 42).result()
            r<   r‘   )rQ   r’   z)RuntimeError: cannot schedule new futuress   runtime-error)	r   r“   rQ   r6   r”   ÚassertInÚdecoder|   r–   )r4   r—   r˜   r™   r   r   r   Ú&test_submit_after_interpreter_shutdown5  s
    
z;ExecutorShutdownTest.test_submit_after_interpreter_shutdownc                s:   ‡ fdd„t dƒD ƒ}ˆ j ¡  x|D ]}| ¡  q&W d S )Nc                s   g | ]}ˆ j  tjd ¡‘qS )gš™™™™™¹?)rT   r\   r    r!   )r]   r@   )r4   r   r   r^   R  s    z=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>é2   )r_   rT   rZ   r   )r4   Úfsr   r   )r4   r   Útest_hang_issue12364Q  s    

z)ExecutorShutdownTest.test_hang_issue12364N)r6   r7   r8   r   rš   r   r    r   r   r   r   r     s   r   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚThreadPoolShutdownTestc             C   s   d S )Nr   )r4   r   r   r   rU   Y  s    z&ThreadPoolShutdownTest._prime_executorc             C   sl   | j  tdd¡ | j  tdd¡ | j  tdd¡ |  t| j jƒd¡ | j  ¡  x| j jD ]}| ¡  qXW d S )Né   rw   é   é   é   é   )rT   r\   r   r|   ÚlenÚ_threadsrZ   Újoin)r4   r#   r   r   r   Útest_threads_terminate\  s    
z-ThreadPoolShutdownTest.test_threads_terminatec             C   sj   t jdd<}|}|  t| ttddƒ¡ƒddddddddddg
¡ W d Q R X x|jD ]}| ¡  qVW d S )	NrJ   )rK   rk   é   r¥   rw   é   r   )	r   rb   r|   ÚlistÚmapÚabsr_   r¨   r©   )r4   ÚerT   r#   r   r   r   Útest_context_manager_shutdowne  s    $z4ThreadPoolShutdownTest.test_context_manager_shutdownc             C   s@   t jdd}| ttddƒ¡ |j}~x|D ]}| ¡  q,W d S )NrJ   )rK   rk   )r   rb   r®   r¯   r_   r¨   r©   )r4   rT   Úthreadsr#   r   r   r   Útest_del_shutdownn  s    
z(ThreadPoolShutdownTest.test_del_shutdownc             C   sP   t jddd}| ttddƒ¡ |j}~x"|D ]}|  |jd¡ | ¡  q.W d S )NrJ   ZSpecialPool)rK   Zthread_name_prefixrk   z^SpecialPool_[0-4]$)	r   rb   r®   r¯   r_   r¨   ÚassertRegexrn   r©   )r4   rT   r²   r#   r   r   r   Útest_thread_names_assignedw  s    

z1ThreadPoolShutdownTest.test_thread_names_assignedc             C   sN   t jdd}| ttddƒ¡ |j}~x"|D ]}|  |jd¡ | ¡  q,W d S )NrJ   )rK   rk   zThreadPoolExecutor-\d+_[0-4]$)	r   rb   r®   r¯   r_   r¨   r´   rn   r©   )r4   rT   r²   r#   r   r   r   Útest_thread_names_default‚  s    
z0ThreadPoolShutdownTest.test_thread_names_defaultN)	r6   r7   r8   rU   rª   r±   r³   rµ   r¶   r   r   r   r   r¡   X  s   			r¡   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚProcessPoolShutdownTestc             C   s   d S )Nr   )r4   r   r   r   rU     s    z'ProcessPoolShutdownTest._prime_executorc             C   st   | j  tdd¡ | j  tdd¡ | j  tdd¡ |  t| j jƒd¡ | j j}| j  ¡  x| ¡ D ]}| ¡  q`W d S )Nr¢   rw   r£   r¤   r¥   r¦   rJ   )	rT   r\   r   r|   r§   Ú
_processesrZ   Úvaluesr©   )r4   Ú	processesÚpr   r   r   Útest_processes_terminate“  s    
z0ProcessPoolShutdownTest.test_processes_terminatec             C   sn   t jdd>}|j}|  t| ttddƒ¡ƒddddddddddg
¡ W d Q R X x| ¡ D ]}| 	¡  qZW d S )	NrJ   )rK   rk   r«   r¥   rw   r¬   r   )
r   rh   r¸   r|   r­   r®   r¯   r_   r¹   r©   )r4   r°   rº   r»   r   r   r   r±   ž  s    $z5ProcessPoolShutdownTest.test_context_manager_shutdownc             C   sj   t jdd}t| ttddƒ¡ƒ |j}|j}|j}|j}~| 	¡  x| 
¡ D ]}| 	¡  qNW | ¡  d S )NrJ   )rK   rk   )r   rh   r­   r®   r¯   r_   Z_queue_management_threadr¸   Z_call_queuer©   r¹   Zjoin_thread)r4   rT   Zqueue_management_threadrº   Z
call_queuer»   r   r   r   r³   §  s    z)ProcessPoolShutdownTest.test_del_shutdownN)r6   r7   r8   rU   r¼   r±   r³   r   r   r   r   r·     s   	r·   )rs   c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )Ú	WaitTestsc             C   sd   | j  tdd¡}| j  tjd¡}tjt||gtjd\}}|  	t
|gƒ|¡ |  	t
t|gƒ|¡ d S )Nr¢   rw   g      ø?)Úreturn_when)rT   r\   r   r    r!   r   rW   ÚCANCELLED_FUTUREÚFIRST_COMPLETEDr|   r>   )r4   Úfuture1Úfuture2ÚdoneZnot_doner   r   r   Útest_first_completedÀ  s    zWaitTests.test_first_completedc             C   sT   | j  tjd¡}tjtt|gtjd\}}|  	t
ttgƒ|¡ |  	t
|gƒ|¡ d S )Ng      ø?)r¾   )rT   r\   r    r!   r   rW   ÚCANCELLED_AND_NOTIFIED_FUTUREÚSUCCESSFUL_FUTURErÀ   r|   r>   )r4   rÁ   ÚfinishedÚpendingr   r   r   Ú+test_first_completed_some_already_completedË  s    
z5WaitTests.test_first_completed_some_already_completedc             C   sr   | j  tdd¡}| j  td¡}| j  tjd¡}tj|||gtjd\}}|  	t
||gƒ|¡ |  	t
|gƒ|¡ d S )Nrw   r¢   g      ø?r¥   )r¾   )rT   r\   r   r$   r    r!   r   rW   ÚFIRST_EXCEPTIONr|   r>   )r4   rÁ   rÂ   Zfuture3rÇ   rÈ   r   r   r   Útest_first_exception×  s    zWaitTests.test_first_exceptionc             C   sl   | j  tdd¡}| j  tjd¡}tjttt	||gtj
d\}}|  ttt	|gƒ|¡ |  tt|gƒ|¡ d S )Nr¢   r   g      ø?)r¾   )rT   r\   Údivmodr    r!   r   rW   rÆ   r¿   rÅ   rÊ   r|   r>   )r4   rÁ   rÂ   rÇ   rÈ   r   r   r   Ú*test_first_exception_some_already_completeã  s    z4WaitTests.test_first_exception_some_already_completec             C   sP   | j  tjd¡}tjt|gtjd\}}|  t	tgƒ|¡ |  t	|gƒ|¡ d S )Nrw   )r¾   )
rT   r\   r    r!   r   rW   ÚEXCEPTION_FUTURErÊ   r|   r>   )r4   rÁ   rÇ   rÈ   r   r   r   Ú'test_first_exception_one_already_failedó  s    z1WaitTests.test_first_exception_one_already_failedc             C   sj   | j  tdd¡}| j  tdd¡}tjttt||gtj	d\}}|  
tttt||gƒ|¡ |  
tƒ |¡ d S )Nrw   r   r¢   )r¾   )rT   r\   rÌ   r   r   rW   rÆ   rÅ   rÎ   ÚALL_COMPLETEDr|   r>   )r4   rÁ   rÂ   rÇ   rÈ   r   r   r   Útest_all_completedý  s    zWaitTests.test_all_completedc             C   sn   | j  tdd¡}| j  tjd¡}tjttt	||gdtj
d\}}|  tttt	|gƒ|¡ |  t|gƒ|¡ d S )Nr£   r¤   rJ   )Útimeoutr¾   )rT   r\   r   r    r!   r   rW   rÅ   rÎ   rÆ   rÐ   r|   r>   )r4   rÁ   rÂ   rÇ   rÈ   r   r   r   Útest_timeout  s    zWaitTests.test_timeoutN)
r6   r7   r8   rÄ   rÉ   rË   rÍ   rÏ   rÑ   rÓ   r   r   r   r   r½   ¾  s   
r½   c               @   s   e Zd Zdd„ ZdS )ÚThreadPoolWaitTestsc          	      sl   t  ¡ ‰ ‡ fdd„‰t ¡ }t d¡ z4‡‡fdd„tdƒD ƒ}ˆ  ¡  tj|tj	d W d t |¡ X d S )Nc                  s   ˆ   ¡  d S )N)rW   r   )r;   r   r   Úfuture_func)  s    z@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcgíµ ÷Æ°>c                s   h | ]}ˆj  ˆ ¡’qS r   )rT   r\   )r]   Úi)rÕ   r4   r   r   ú	<setcomp>.  s    z>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>éd   )r¾   )
Ú	threadingr:   r&   ÚgetswitchintervalÚsetswitchintervalr_   r>   r   rW   rÐ   )r4   ZoldswitchintervalrŸ   r   )r;   rÕ   r4   r   Útest_pending_calls_race%  s    
z+ThreadPoolWaitTests.test_pending_calls_raceN)r6   r7   r8   rÜ   r   r   r   r   rÔ   #  s   rÔ   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚAsCompletedTestsc             C   sV   | j  tdd¡}| j  tdd¡}tt ttt||g¡ƒ}|  	tttt||gƒ|¡ d S )Nrw   r¢   r¤   r£   )
rT   r\   r   r>   r   Úas_completedrÅ   rÎ   rÆ   r|   )r4   rÁ   rÂ   Ú	completedr   r   r   Útest_no_timeout=  s    z AsCompletedTests.test_no_timeoutc             C   sv   | j  tjd¡}tƒ }y.x(tjttt	|gddD ]}| 
|¡ q0W W n tjk
rZ   Y nX |  tttt	gƒ|¡ d S )Nrw   r   )rÒ   )rT   r\   r    r!   r>   r   rÞ   rÅ   rÎ   rÆ   ÚaddÚTimeoutErrorr|   )r4   rÁ   Zcompleted_futuresr‚   r   r   r   Útest_zero_timeoutM  s     z"AsCompletedTests.test_zero_timeoutc             C   s@   | j  tjd¡}dd„ t t |d¡¡D ƒ}|  t	|ƒd¡ d S )Nrw   c             S   s   g | ]}|‘qS r   r   )r]   r   r   r   r   r^   f  s    z;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>r¥   r¬   )
rT   r\   r    r!   r   rÞ   Ú	itertoolsÚrepeatr|   r§   )r4   rÁ   rß   r   r   r   Útest_duplicate_futures`  s    z'AsCompletedTests.test_duplicate_futuresc          	   C   sà   dd„ t dƒD ƒ}| ttd¡ | ttdd¡ |  tj¡@ x8tj|ddD ]&}| 	|¡ t
 |¡}~|  |ƒ ¡ qRW W d Q R X |d  d	¡ xFt |¡D ]8}| 	|¡ t
 |¡}~|  |ƒ ¡ |r |d  d	¡ q W d S )
Nc             S   s   g | ]
}t ƒ ‘qS r   )r   )r]   r@   r   r   r   r^   m  s    zGAsCompletedTests.test_free_reference_yielded_future.<locals>.<listcomp>é   )r   r   )r   r   r   )rÒ   rC   )r_   r…   r   r	   r
   r€   r   râ   rÞ   ÚremoveÚweakrefÚrefÚassertIsNoneÚ
set_result)r4   Úfutures_listr‚   Úwrr   r   r   Ú"test_free_reference_yielded_futurej  s"    



z3AsCompletedTests.test_free_reference_yielded_futurec          	   C   sL   t tttg}|  tj¡}ttj|ddƒ W d Q R X |  	t
|jƒd¡ d S )Nr   )rÒ   z2 (of 4) futures unfinished)rÅ   ÚPENDING_FUTUREÚRUNNING_FUTURErÆ   r€   r   râ   r­   rÞ   r|   Ústrr   )r4   rí   rŠ   r   r   r   Ú"test_correct_timeout_exception_msg  s
    z3AsCompletedTests.test_correct_timeout_exception_msgN)r6   r7   r8   rà   rã   ræ   rï   ró   r   r   r   r   rÝ   ;  s
   
rÝ   c               @   s\   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	j
jdd„ ƒZdd„ Zdd„ ZdS )ÚExecutorTestc             C   s$   | j  tdd¡}|  d| ¡ ¡ d S )Nrw   rç   é   )rT   r\   r   r|   r   )r4   r‚   r   r   r   Útest_submit‘  s    zExecutorTest.test_submitc          	   C   s    | j jtddd}|  d| ¡ ¡ | j jtdddd}|  | ¡ ddddœf¡ | j jtdd	}|  | ¡ d
ddif¡ |  t¡ | j jdd W d Q R X d S )Nrw   rç   )r   é   r¬   r¥   )r4   Úfn)r¬   )rø   Úargr   rù   )rù   )rT   r\   r   r|   r   r   r€   Ú	TypeError)r4   r‚   r   r   r   Útest_submit_keyword•  s    z ExecutorTest.test_submit_keywordc          	   C   sx   |   t| j ttdƒtdƒ¡ƒttttdƒtdƒƒƒ¡ |   t| jjttdƒtdƒddƒttttdƒtdƒƒƒ¡ d S )Né
   r¥   )Ú	chunksize)r|   r­   rT   r®   r   r_   )r4   r   r   r   Útest_mapŸ  s    zExecutorTest.test_mapc             C   sR   | j  tddddgddddg¡}|  | ¡ d¡ |  | ¡ d¡ |  t|j¡ d S )Nr¬   rw   r¥   r   rJ   )r   r¬   )rT   r®   rÌ   r|   Ú__next__r€   ÚZeroDivisionError)r4   rÖ   r   r   r   Útest_map_exception¨  s     zExecutorTest.test_map_exceptionc             C   sl   g }y2x,| j jtjdddgddD ]}| |¡ q"W W n tjk
rL   Y nX |  d¡ |  d d g|¡ d S )Nr   r£   rJ   )rÒ   zexpected TimeoutError)	rT   r®   r    r!   r…   r   râ   r   r|   )r4   ÚresultsrÖ   r   r   r   Útest_map_timeout®  s    
zExecutorTest.test_map_timeoutc             C   s(   | j  tdg| jd  ¡ | j  ¡  d S )Nrw   r¬   )rT   r®   rò   rR   rZ   )r4   r   r   r   Útest_shutdown_race_issue12456¼  s    z*ExecutorTest.test_shutdown_race_issue12456c                sN   t ƒ }t ¡ ‰ t |‡ fdd„¡}| j |j¡ ~ˆ jdd}|  	|d¡ d S )Nc                s   ˆ   ¡ S )N)r>   )Úobj)Úmy_object_collectedr   r   Ú<lambda>Ê  ó    z7ExecutorTest.test_no_stale_references.<locals>.<lambda>g      @)rÒ   z-Stale reference not collected within timeout.)
r3   rÙ   r:   ré   rê   rT   r\   r5   rW   rˆ   )r4   Z	my_objectZmy_object_callbackZ	collectedr   )r  r   Útest_no_stale_referencesÃ  s    z%ExecutorTest.test_no_stale_referencesc          
   C   s6   x0dD ](}|   td¡ | j|d W d Q R X qW d S )N)r   éÿÿÿÿz"max_workers must be greater than 0)rK   )ÚassertRaisesRegexr0   rQ   )r4   Znumberr   r   r   Útest_max_workers_negativeÓ  s    
z&ExecutorTest.test_max_workers_negativec             C   s8   x2| j  ttdƒ¡D ]}t |¡}~|  |ƒ ¡ qW d S )Nrü   )rT   r®   rA   r_   ré   rê   rë   )r4   r  rî   r   r   r   Útest_free_referenceÚ  s    
z ExecutorTest.test_free_referenceN)r6   r7   r8   rö   rû   rþ   r  r  r  rC   rD   Zcpython_onlyr	  r  r  r   r   r   r   rô   Ž  s   
	rô   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚThreadPoolExecutorTestc                sD   g ‰ ‡ fdd„}| j  |tdƒ¡ | j jdd |  ˆ tdƒ¡ dS )zTests verifying issue 11777.c                s   ˆ   | ¡ d S )N)r…   )Ún)rÇ   r   r   Úrecord_finishedç  s    zRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedrü   T)rW   N)rT   r®   r_   rZ   ZassertCountEqual)r4   r  r   )rÇ   r   Ú"test_map_submits_without_iterationä  s
    z9ThreadPoolExecutorTest.test_map_submits_without_iterationc             C   s&   |   ¡ }|  |jt ¡ pdd ¡ d S )Nr¬   rJ   )rQ   r|   Z_max_workersÚosÚ	cpu_count)r4   rT   r   r   r   Útest_default_workersî  s    z+ThreadPoolExecutorTest.test_default_workersN)r6   r7   r8   r  r  r   r   r   r   r  ã  s   
r  c               @   sR   e Zd Ze ejdkd¡dd„ ƒZdd„ Zdd„ Z	e
d	d
„ ƒZdd„ Zdd„ ZdS )ÚProcessPoolExecutorTestre   zWindows-only process limitc          	   C   s(   |   td¡ tjdd W d Q R X d S )Nzmax_workers must be <= 61é>   )rK   )r  r0   r   rh   )r4   r   r   r   Útest_max_workers_too_largeö  s    z2ProcessPoolExecutorTest.test_max_workers_too_largec             C   sd   | j  tjd¡g}tt| j j ¡ ƒƒ}| ¡  x|D ]}|  	t
|j¡ q4W |  	t
| j jtdd¡ d S )Nr¥   rw   rç   )rT   r\   r    r!   ÚnextÚiterr¸   r¹   Ú	terminater€   r   r   r   )r4   r   r»   Zfutr   r   r   Útest_killed_childü  s    
z)ProcessPoolExecutorTest.test_killed_childc          	      s¬   ‡ fdd„}t tttdƒtdƒƒƒ}ˆ  t ˆ jjttdƒtdƒddƒ|¡ ˆ  t ˆ jjttdƒtdƒddƒ|¡ ˆ  t ˆ jjttdƒtdƒddƒ|¡ ˆ  t|¡ d S )Nc                  s$   t ˆ jjttdƒtdƒddƒ d S )Né(   r
  )rý   )r­   rT   r®   r   r_   r   )r4   r   r   Úbad_map	  s    z;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_mapr  r£   )rý   rž   )r­   r®   r   r_   r|   rT   r€   r0   )r4   r  rê   r   )r4   r   Útest_map_chunksize  s    z*ProcessPoolExecutorTest.test_map_chunksizec             C   s   t dƒ‚d S )Né{   )rŽ   )rt   r   r   r   Ú_test_traceback  s    z'ProcessPoolExecutorTest._test_tracebackc          	   C   sÎ   | j  | j¡}|  t¡}| ¡  W d Q R X |j}|  t|ƒt	¡ |  
|jd¡ |j}|  t|ƒtjj¡ |  d|j¡ tj ¡ 2}y|‚W n" t	k
r®   tjt ¡ Ž  Y nX W d Q R X |  d| ¡ ¡ d S )N)r  z&raise RuntimeError(123) # some comment)rT   r\   r   r€   r"   r   r   ZassertIsrp   rŽ   r|   r   Ú	__cause__r   ZprocessZ_RemoteTracebackr›   ÚtbrC   rD   Úcaptured_stderrr&   Ú
excepthookÚexc_infoÚgetvalue)r4   r‚   rŠ   ÚexcÚcauseÚf1r   r   r   Útest_traceback  s     z&ProcessPoolExecutorTest.test_tracebackc             C   s8   t | jƒ}| j t|¡}| ¡  |  |jjdd¡ d S )Nr¬   )rÒ   )	r9   r<   rT   r\   Úidr   rˆ   r;   rW   )r4   r  r‚   r   r   r   Útest_ressources_gced_in_workers2  s    
z7ProcessPoolExecutorTest.test_ressources_gced_in_workersN)r6   r7   r8   ÚunittestZ
skipUnlessr&   rf   r  r  r  Úclassmethodr   r*  r,  r   r   r   r   r  ô  s   r  c              C   s   dd l } |  ¡ t_d S )Nr   )ÚioÚStringIOr&   Ústderr)r/  r   r   r   Úhide_process_stderrA  s    r2  c             C   s*   | rt  | ¡ ddl}| ¡  | ¡  dS )zInduces a segfault.r   N)r    r!   ÚfaulthandlerZdisableZ_sigsegv)Údelayr3  r   r   r   Ú_crashF  s
    
r5  c               C   s   t  d¡ dS )z#Induces a sys exit with exitcode 1.r¬   N)r&   Úexitr   r   r   r   Ú_exitO  s    r7  c             C   s   t ƒ  | ƒ ‚dS )z-Function that raises an Exception in process.N)r2  )ZErrr   r   r   Ú_raise_errorT  s    r8  c             C   s   t ƒ  | ƒ S )z(Function that returns a instance of cls.)r2  )rt   r   r   r   Ú_return_instanceZ  s    r9  c               @   s   e Zd ZdZdd„ ZdS )ÚCrashAtPicklez5Bad object that triggers a segfault at pickling time.c             C   s
   t ƒ  d S )N)r5  )r4   r   r   r   Ú
__reduce__b  s    zCrashAtPickle.__reduce__N)r6   r7   r8   Ú__doc__r;  r   r   r   r   r:  `  s   r:  c               @   s   e Zd ZdZdd„ ZdS )ÚCrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.c             C   s   t dfS )Nr   )r5  )r4   r   r   r   r;  h  s    zCrashAtUnpickle.__reduce__N)r6   r7   r8   r<  r;  r   r   r   r   r=  f  s   r=  c               @   s   e Zd ZdZdd„ ZdS )ÚExitAtPicklez9Bad object that triggers a process exit at pickling time.c             C   s
   t ƒ  d S )N)r7  )r4   r   r   r   r;  n  s    zExitAtPickle.__reduce__N)r6   r7   r8   r<  r;  r   r   r   r   r>  l  s   r>  c               @   s   e Zd ZdZdd„ ZdS )ÚExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.c             C   s   t dfS )Nr   )r7  )r4   r   r   r   r;  t  s    zExitAtUnpickle.__reduce__N)r6   r7   r8   r<  r;  r   r   r   r   r?  r  s   r?  c               @   s   e Zd ZdZdd„ ZdS )ÚErrorAtPicklez3Bad object that triggers an error at pickling time.c             C   s   ddl m} |dƒ‚d S )Nr   )r   zError in pickle)Úpickler   )r4   r   r   r   r   r;  z  s    zErrorAtPickle.__reduce__N)r6   r7   r8   r<  r;  r   r   r   r   r@  x  s   r@  c               @   s   e Zd ZdZdd„ ZdS )ÚErrorAtUnpicklez5Bad object that triggers an error at unpickling time.c             C   s   ddl m} t|ffS )Nr   )ÚUnpicklingError)rA  rC  r8  )r4   rC  r   r   r   r;    s    zErrorAtUnpickle.__reduce__N)r6   r7   r8   r<  r;  r   r   r   r   rB    s   rB  c               @   s4   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
S )ÚExecutorDeadlockTesté   c             C   s   t  |¡ |S )N)r    r!   )rt   r   r4  r   r   r   Ú	_sleep_id‰  s    
zExecutorDeadlockTest._sleep_idc          	   C   s˜   dd l }ddlm} |dd$}|j|d | d¡ | ¡ }W d Q R X x|j ¡ D ]}| ¡  qTW |j	dd t
d|› tjd |  d	|› ¡ d S )
Nr   )ÚTemporaryFilezw+)Úmode)ÚfileT)rW   z
Traceback:
 zExecutor deadlock:

)r3  ZtempfilerG  Zdump_tracebackÚseekÚreadr¸   r¹   r  rZ   r%   r&   Ú
__stderr__r   )r4   rT   r3  rG  r   r"  r»   r   r   r   Ú_fail_on_deadlockŽ  s    
z&ExecutorDeadlockTest._fail_on_deadlockc             C   sh  | j jdd ttƒ ftdfttƒ ftdfttƒ ftdfttƒ ftdft	dtdft
dtd	fttftd
fttftdfttftdfttftdfttftdfttftdfg}x¼|D ]´\}}}}|  |¡˜ tj ¡ ‚ | jdt| jƒd}|j|f|žŽ }|  |¡< y|j| jd W n" tjk
r4   |  |¡ Y nX W d Q R X |jdd W d Q R X W d Q R X q¬W d S )NT)rW   zerror at task picklezexit at task unpicklezerror at task unpicklezcrash at task unpickler   z%crash during func execution on workerz$exit during func execution on workerz%error during func execution on workerz$crash during result pickle on workerz#exit during result pickle on workerz$error during result pickle on workerz.error during result unpickle in result_handlerz-exit during result unpickle in result_handlerrw   )rK   rL   )rÒ   )rT   rZ   r+  r@  r   r?  r   rB  r=  r5  r7  Ú
SystemExitr8  rŽ   r9  r:  r>  ZsubTestrC   rD   r#  rQ   r   r<   r\   r€   r   ÚTIMEOUTr   râ   rM  )r4   Zcrash_casesÚfuncr   Úerrorrn   rT   Zresr   r   r   Ú
test_crash¡  sH    


zExecutorDeadlockTest.test_crashc          
   C   sp   | j jdd | jdt| jƒdD}|| _ |jtdd}|jdd |  t¡ | 	¡  W d Q R X W d Q R X d S )NT)rW   rw   )rK   rL   gš™™™™™¹?)r4  )
rT   rZ   rQ   r   r<   r\   r5  r€   r   r   )r4   rT   r   r   r   r   Útest_shutdown_deadlockÕ  s    z+ExecutorDeadlockTest.test_shutdown_deadlockN)	r6   r7   r8   rO  r.  rF  rM  rR  rS  r   r   r   r   rD  †  s
   4rD  c               @   sœ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%S )&ÚFutureTestsc                s:   d ‰ ‡ fdd„}t ƒ }| |¡ | d¡ |  dˆ ¡ d S )Nc                s   |   ¡ ‰ d S )N)r   )Úcallback_future)Úcallback_resultr   r   rø   ë  s    z6FutureTests.test_done_callback_with_result.<locals>.fnrJ   )r   Úadd_done_callbackrì   r|   )r4   rø   r   r   )rV  r   Útest_done_callback_with_resulté  s    

z*FutureTests.test_done_callback_with_resultc                s@   d ‰ ‡ fdd„}t ƒ }| |¡ | tdƒ¡ |  dˆ j¡ d S )Nc                s   |   ¡ ‰ d S )N)r   )rU  )Úcallback_exceptionr   r   rø   ö  s    z9FutureTests.test_done_callback_with_exception.<locals>.fnrC   )rC   )r   rW  Úset_exceptionr"   r|   r   )r4   rø   r   r   )rY  r   Ú!test_done_callback_with_exceptionô  s    
z-FutureTests.test_done_callback_with_exceptionc                s<   d ‰ ‡ fdd„}t ƒ }| |¡ |  | ¡ ¡ |  ˆ ¡ d S )Nc                s   |   ¡ ‰ d S )N)Ú	cancelled)rU  )Úwas_cancelledr   r   rø     s    z6FutureTests.test_done_callback_with_cancel.<locals>.fn)r   rW  rˆ   Úcancel)r4   rø   r   r   )r]  r   Útest_done_callback_with_cancelÿ  s    
z*FutureTests.test_done_callback_with_cancelc          	      s‚   t j ¡ n}d‰d‰ ‡fdd„}‡ fdd„}tƒ }| |¡ | |¡ | d¡ |  ˆ¡ |  ˆ ¡ |  d| ¡ ¡ W d Q R X d S )NFc                s   d‰ t dƒ‚d S )NTzdoh!)r"   )rU  )Úraising_was_calledr   r   Ú
raising_fn  s    z9FutureTests.test_done_callback_raises.<locals>.raising_fnc                s   d‰ d S )NTr   )rU  )Úfn_was_calledr   r   rø     s    z1FutureTests.test_done_callback_raises.<locals>.fnrJ   zException: doh!)	rC   rD   r#  r   rW  rì   rˆ   r›   r&  )r4   r1  ra  rø   r   r   )rb  r`  r   Útest_done_callback_raises
  s    




z%FutureTests.test_done_callback_raisesc                s:   d ‰ ‡ fdd„}t ƒ }| d¡ | |¡ |  dˆ ¡ d S )Nc                s   |   ¡ ‰ d S )N)r   )rU  )rV  r   r   rø   "  s    z=FutureTests.test_done_callback_already_successful.<locals>.fnrJ   )r   rì   rW  r|   )r4   rø   r   r   )rV  r   Ú%test_done_callback_already_successful   s    

z1FutureTests.test_done_callback_already_successfulc                s@   d ‰ ‡ fdd„}t ƒ }| tdƒ¡ | |¡ |  dˆ j¡ d S )Nc                s   |   ¡ ‰ d S )N)r   )rU  )rY  r   r   rø   -  s    z9FutureTests.test_done_callback_already_failed.<locals>.fnrC   )rC   )r   rZ  r"   rW  r|   r   )r4   rø   r   r   )rY  r   Ú!test_done_callback_already_failed+  s    
z-FutureTests.test_done_callback_already_failedc                s<   d ‰ ‡ fdd„}t ƒ }|  | ¡ ¡ | |¡ |  ˆ ¡ d S )Nc                s   |   ¡ ‰ d S )N)r\  )rU  )r]  r   r   rø   8  s    z<FutureTests.test_done_callback_already_cancelled.<locals>.fn)r   rˆ   r^  rW  )r4   rø   r   r   )r]  r   Ú$test_done_callback_already_cancelled6  s    
z0FutureTests.test_done_callback_already_cancelledc          	   C   s\   t j ¡ H}dd„ }tƒ }| d¡ | |¡ |  d| ¡ ¡ |  d| ¡ ¡ W d Q R X d S )Nc             S   s   t dƒ‚d S )Nzdoh!)r"   )rU  r   r   r   ra  C  s    zKFutureTests.test_done_callback_raises_already_succeeded.<locals>.raising_fnrJ   zexception calling callback forzdoh!)rC   rD   r#  r   rì   rW  r›   r&  )r4   r1  ra  r   r   r   r   Ú+test_done_callback_raises_already_succeededA  s    

z7FutureTests.test_done_callback_raises_already_succeededc             C   sd   |   ttƒd¡ |   ttƒd¡ |   ttƒd¡ |   ttƒd¡ |   ttƒd¡ |   ttƒd¡ d S )Nz%<Future at 0x[0-9a-f]+ state=pending>z%<Future at 0x[0-9a-f]+ state=running>z'<Future at 0x[0-9a-f]+ state=cancelled>z5<Future at 0x[0-9a-f]+ state=finished raised OSError>z3<Future at 0x[0-9a-f]+ state=finished returned int>)r´   Úreprrð   rñ   r¿   rÅ   rÎ   rÆ   )r4   r   r   r   Ú	test_reprQ  s    



zFutureTests.test_reprc             C   sî   t td}t td}t td}t td}t ttƒ d}t tdd}|  | ¡ ¡ |  	|j
t¡ |  | ¡ ¡ |  	|j
t¡ |  | ¡ ¡ |  	|j
t¡ |  | ¡ ¡ |  	|j
t¡ |  | ¡ ¡ |  	|j
t¡ |  | ¡ ¡ |  	|j
t¡ d S )N)r   )r   r   rJ   )r   r   )r   r   r   r   r	   r
   ÚOSErrorrˆ   r^  r|   r   r•   )r4   r)  Úf2Zf3Zf4Zf5Zf6r   r   r   Útest_cancelb  s$    



zFutureTests.test_cancelc             C   sX   |   t ¡ ¡ |   t ¡ ¡ |  t ¡ ¡ |  t ¡ ¡ |   t ¡ ¡ |   t ¡ ¡ d S )N)	r•   rð   r\  rñ   rˆ   r¿   rÅ   rÎ   rÆ   )r4   r   r   r   Útest_cancelled|  s    zFutureTests.test_cancelledc             C   sX   |   t ¡ ¡ |   t ¡ ¡ |  t ¡ ¡ |  t ¡ ¡ |  t ¡ ¡ |  t ¡ ¡ d S )N)	r•   rð   rÃ   rñ   rˆ   r¿   rÅ   rÎ   rÆ   )r4   r   r   r   Ú	test_done„  s    zFutureTests.test_donec             C   sX   |   t ¡ ¡ |  t ¡ ¡ |   t ¡ ¡ |   t ¡ ¡ |   t ¡ ¡ |   t ¡ ¡ d S )N)	r•   rð   Zrunningrˆ   rñ   r¿   rÅ   rÎ   rÆ   )r4   r   r   r   Útest_runningŒ  s    zFutureTests.test_runningc             C   sz   | j tjtjdd | j tjtjdd | j tjtjdd | j tjtjdd | j t	t
jdd |  tjddd¡ d S )Nr   )rÒ   r   )r€   r   râ   rð   r   rñ   ÚCancelledErrorr¿   rÅ   rj  rÎ   r|   rÆ   )r4   r   r   r   Útest_result_with_timeout”  s    z$FutureTests.test_result_with_timeoutc                sJ   ‡ fdd„}t td‰ tj|d}| ¡  |  ˆ jddd¡ | ¡  d S )Nc                  s   t  d¡ ˆ  d¡ d S )Nr¬   r   )r    r!   rì   r   )r)  r   r   Únotification¢  s    
z:FutureTests.test_result_with_success.<locals>.notification)r   )ÚtargetrJ   )rÒ   r   )r   r   rÙ   ÚThreadÚstartr|   r   r©   )r4   rr  r#   r   )r)  r   Útest_result_with_success   s    
z$FutureTests.test_result_with_successc                sJ   ‡ fdd„}t td‰ tj|d}| ¡  | jtjˆ jdd | 	¡  d S )Nc                  s   t  d¡ ˆ  ¡  d S )Nr¬   )r    r!   r^  r   )r)  r   r   rr  °  s    
z9FutureTests.test_result_with_cancel.<locals>.notification)r   )rs  rJ   )rÒ   )
r   r   rÙ   rt  ru  r€   r   rp  r   r©   )r4   rr  r#   r   )r)  r   Útest_result_with_cancel®  s    
z#FutureTests.test_result_with_cancelc             C   s€   | j tjtjdd | j tjtjdd | j tjtjdd | j tjtjdd |  	t
tjddtƒ¡ |  tjddd ¡ d S )Nr   )rÒ   )r€   r   râ   rð   r   rñ   rp  r¿   rÅ   rˆ   Ú
isinstancerÎ   rj  r|   rÆ   )r4   r   r   r   Útest_exception_with_timeout¼  s    z'FutureTests.test_exception_with_timeoutc                sN   ‡ fdd„}t td‰ tj|d}| ¡  |  tˆ jddtƒ¡ | 	¡  d S )Nc            	      s8   t  d¡ ˆ j tˆ _tƒ ˆ _ˆ j ¡  W d Q R X d S )Nr¬   )r    r!   Z
_conditionr
   r   rj  r   Z
notify_allr   )r)  r   r   rr  Ê  s
    
z=FutureTests.test_exception_with_success.<locals>.notification)r   )rs  rJ   )rÒ   )
r   r   rÙ   rt  ru  rˆ   rx  r   rj  r©   )r4   rr  r#   r   )r)  r   Útest_exception_with_successÉ  s    
z'FutureTests.test_exception_with_successN)r6   r7   r8   rX  r[  r_  rc  rd  re  rf  rg  ri  rl  rm  rn  ro  rq  rv  rw  ry  rz  r   r   r   r   rT  è  s$   rT  c               C   s"   zt j t¡ W d t j ¡  X d S )N)rC   rD   Zrun_unittestr6   rG   r   r   r   r   Ú	test_mainÚ  s    r{  Ú__main__)N)N)YZtest.supportrC   rD   Úimport_moduleZtest.support.script_helperr   r‹   rä   r/   Zlogging.handlersr   r  r†   r&   rÙ   r    r-  ré   rA  r   Z
concurrentr   Zconcurrent.futures._baser   r   r   r	   r
   r   r   Zconcurrent.futures.processr   Zmultiprocessingr   r   rð   rñ   r¿   rÅ   rj  rÎ   rÆ   r+   r   r   r$   r*   r,   r-   r2   Úobjectr3   r9   rA   ZTestCaserB   rI   ra   rc   ri   rj   ru   rv   r~   r   r¡   r·   r½   rÔ   rÝ   rô   r  r  r2  r5  r7  r8  r9  r:  r=  r>  r?  r@  rB  rD  rT  Zreap_threadsr{  r6   r   r   r   r   Ú<module>   s¾   $





		*

;@7)
e
PUH

	\
 s
