HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/supervisor/tests/__pycache__/test_process.cpython-36.pyc
3

�k�`v��@sjddlZddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZddl	m
Z
ddl	mZddl	mZddl	mZdd	l	mZdd
l	mZddl	mZddl	mZdd
l	mZddl	mZddlmZddlmZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�dej�Z Gdd�de�Z!Gdd�dej�Z"dS)�N)�as_bytes)�maxint)�Mock�patch�sentinel)�DummyOptions)�DummyPConfig)�DummyProcess)�DummyPGroupConfig)�DummyDispatcher)�
DummyEvent)�DummyFCGIGroupConfig)�DummySocketConfig)�DummyProcessGroup)�DummyFCGIProcessGroup)�
Subprocess)�
BadCommandc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�S)��SubprocessTestscCsddlm}|S)Nr)r)�supervisor.processr)�selfr�r�"/usr/lib/python3.6/test_process.py�_getTargetClassszSubprocessTests._getTargetClasscOs|j�||�S)N)r)r�arg�kwrrr�_makeOneszSubprocessTests._makeOnecCsddlm}|�dS)Nr)�clear)�supervisor.eventsr)rrrrr�tearDown"szSubprocessTests.tearDowncCsNddlm}ddlm}x0|jj�D]"\}}t|t�r$|j||�|�q$WdS)Nr)�
ProcessStates)�getProcessStateDescription)	�supervisor.statesrrr �__dict__�items�
isinstance�int�assertEqual)rrr Z	statename�coderrr�test_getProcessStateDescription&s

z/SubprocessTests.test_getProcessStateDescriptioncCs�t�}t|ddddd�}|j|�}|j|j|�|j|jj|�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d�|j
|j�|j
|j�|j|j
d�|j|ji�|j|ji�|j|jd�dS)N�catzbin/catz/tmp/temp123.logz/tmp/temp456.log)�stdout_logfile�stderr_logfiler)rrrr&�config�options�	laststart�pidZlaststop�delay�assertFalse�administrative_stop�killing�backoff�pipes�dispatchers�spawnerr)rr-r,�instancerrr�	test_ctor-s$
zSubprocessTests.test_ctorcCsHt�}t|dd�}|j|�}t|�}|j|jd��|j|jd��dS)Nr)zbin/catz<Subprocess atzwith name cat in state STOPPED>)rrr�repr�
assertTrue�
startswith�endswith)rr-r,r8�srrr�	test_reprAs
zSubprocessTests.test_reprcCsht�}t|dd�}|j|�}tdd�tdd�d�|_|j�|j|jdjd�|j|jdjd	�dS)
N�testz/testT)�readable)�writable)r�rrCF)rrrrr6�
reopenlogsr&�
logs_reopened)rr-r,r8rrr�test_reopenlogsIs
zSubprocessTests.test_reopenlogscCsht�}t|dd�}|j|�}tdd�tdd�d�|_|j�|j|jdjd�|j|jdjd	�dS)
Nr@z/testT)rA)rB)rrCrrCF)rrrrr6�
removelogsr&Zlogs_removed)rr-r,r8rrr�test_removelogsSs
zSubprocessTests.test_removelogscCsjt�}t|ddddd�}|j|�}tdd�tdd�d	�|_|j�|j|jd
j�|j|jdj�dS)Nr@z/testz/tmp/fooz/tmp/bar)r*r+T)rA)rB)rrCrrC)	rrrrr6Zdrainr;Zread_event_handledZwrite_event_handled)rr-r,r8rrr�
test_drain]s
zSubprocessTests.test_draincCs.t�}t|dd�}|j|�}|jt|j�dS)NZ
extraquotezextraquote")rrr�assertRaisesr�get_execv_args)rr-r,r8rrr�*test_get_execv_args_bad_command_extraquoteis
z:SubprocessTests.test_get_execv_args_bad_command_extraquotecCs.t�}t|dd�}|j|�}|jt|j�dS)N�empty�)rrrrJrrK)rr-r,r8rrr�%test_get_execv_args_bad_command_emptyos
z5SubprocessTests.test_get_execv_args_bad_command_emptycCs.t�}t|dd�}|j|�}|jt|j�dS)NZwhitespaceonlyz 	 )rrrrJrrK)rr-r,r8rrr�.test_get_execv_args_bad_command_whitespaceonlyus
z>SubprocessTests.test_get_execv_args_bad_command_whitespaceonlycCs:t�}t|dd�}|j|�}|j�}|j|ddgf�dS)N�nottherez	/notthere)rrrrKr&)rr-r,r8�argsrrr�test_get_execv_args_abs_missing{s

z/SubprocessTests.test_get_execv_args_abs_missingcCs<t�}t|dd�}|j|�}|j�}|j|dddgf�dS)NrQz/notthere "an argument"z	/nottherezan argument)rrrrKr&)rr-r,r8rRrrr�*test_get_execv_args_abs_withquotes_missing�s

z:SubprocessTests.test_get_execv_args_abs_withquotes_missingcCs:t�}t|dd�}|j|�}|j�}|j|ddgf�dS)NrQ)rrrrKr&)rr-r,r8rRrrr�test_get_execv_args_rel_missing�s

z/SubprocessTests.test_get_execv_args_rel_missingcCs<t�}t|dd�}|j|�}|j�}|j|dddgf�dS)NrQznotthere "an argument"zan argument)rrrrKr&)rr-r,r8rRrrr�*test_get_execv_args_rel_withquotes_missing�s

z:SubprocessTests.test_get_execv_args_rel_withquotes_missingcCs`d}t�}t|d|�}|j|�}|j�}|jt|�d�|j|dd�|j|dddg�dS)Nz/bin/sh foo�sh�rz/bin/shrC�foo)rrrrKr&�len)r�
executabler-r,r8rRrrr�test_get_execv_args_abs�s
z'SubprocessTests.test_get_execv_args_abscCs`d}t�}t|d|�}|j|�}|j�}|jt|�d�|j|dd�|j|dddg�dS)Nzsh foorWrXrz/bin/shrCrY)rrrrKr&rZ)rr[r-r,r8rRrrr�test_get_execv_args_rel�s
z'SubprocessTests.test_get_execv_args_relcs�tj��x}tjj|j�\�}d|}t�}t|d|�}�fdd�|_|j	|�}|j
�}|j|d|j�|j|d|dg�WdQRXdS)Nz%s foorWcs�gS)Nrr)�dirnamerr�<lambda>�szUSubprocessTests.test_get_execv_args_rel_searches_using_pconfig_path.<locals>.<lambda>rrCrY)�tempfileZNamedTemporaryFile�os�path�split�namerr�get_pathrrKr&)r�f�basenamer[r-r,r8rRr)r^r�3test_get_execv_args_rel_searches_using_pconfig_path�s

zCSubprocessTests.test_get_execv_args_rel_searches_using_pconfig_pathcCsLt�}t|dd�}|j|�}|jd�|j|jd�|j|jjdd�dS)Nr@z/testrYrz
spawnerr: foo)rrrZrecord_spawnerrr&r7�logger�data)rr-r,r8rrr�test_record_spawnerr�s

z$SubprocessTests.test_record_spawnerrcCsrt�}t|dd�}|j|�}d|_ddlm}|j|_|j�}|j	|d�|j	|j
jdd�|j	|j|j�dS)NrWz/bin/shTr)rzprocess 'sh' already running)rrrr/r!r�RUNNING�state�spawnr&rirj)rr-r,r8r�resultrrr�test_spawn_already_running�s
z*SubprocessTests.test_spawn_already_runningc	st�}t|dd�}|j|�}ddlm}|j|_ddlm}g�|j	|j
�fdd��|j�}|j|d�|j|j
d�|j|jjdd	�|j|j�|j|j�ddlm}|j|j|j�|jt��d
��d}�d}|j|j|j�|j|j|j�dS)NZbadz
/bad/filenamer)r)�eventscs
�j|�S)N)�append)�x)�Lrrr_�szBSubprocessTests.test_spawn_fail_check_execv_args.<locals>.<lambda>zbad filenamezspawnerr: bad filenamerXrC)rrrr!r�BACKOFFrm�
supervisorrq�	subscribe�ProcessStateEventrnr&r7rirjr;r0r4rZ�	__class__�ProcessStateStartingEvent�ProcessStateBackoffEvent)	rr-r,r8rrqro�event1�event2r)rtr� test_spawn_fail_check_execv_args�s*
z0SubprocessTests.test_spawn_fail_check_execv_argsc	st�}ttjtjtj��|_t|dd�}|j|�}ddl	m
}|j|_ddl
m}g�|j|j�fdd��|j�}|j|d�|j|jd�|j|jjdd	�|j|j�|j|j�ddl	m
}|j|j|j�|jt��d
��\}}|j|j|j�|j|j|j�dS)N�goodz/good/filenamer)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szCSubprocessTests.test_spawn_fail_make_pipes_emfile.<locals>.<lambda>z#too many open files to spawn 'good'z-spawnerr: too many open files to spawn 'good'rX)r�OSError�errnoZEMFILEra�strerror�make_pipes_exceptionrrr!rrurmrvrqrwrxrnr&r7rirjr;r0r4rZryrzr{)	rr-r,r8rrqror|r}r)rtr�!test_spawn_fail_make_pipes_emfile�s0
z1SubprocessTests.test_spawn_fail_make_pipes_emfilec
st�}ttjtjtj��|_t|dd�}|j|�}ddl	m
}|j|_ddl
m}g�|j|j�fdd��|j�}|j|d�d}|j|j|�|j|jjdd	|�|j|j�|j|j�ddl	m
}|j|j|j�|jt��d
��\}}	|j|j|j�|j|	j|j�dS)Nrz/good/filenamer)r)rqcs
�j|�S)N)rr)rs)rtrrr_szBSubprocessTests.test_spawn_fail_make_pipes_other.<locals>.<lambda>z2unknown error making dispatchers for 'good': EPERMzspawnerr: %srX)rr�r��EPERMrar�r�rrr!rrurmrvrqrwrxrnr&r7rirjr;r0r4rZryrzr{)
rr-r,r8rrqro�msgr|r}r)rtr� test_spawn_fail_make_pipes_other�s.
z0SubprocessTests.test_spawn_fail_make_pipes_othercst�}t|dddd�}dd�}||_|j|�}ddlm}|j|_dd	lm	}g�|j
|j�fd
d��|j�}|j
|d�d}|j
|j|�|j
|jjdd
|�|j|j�|j|j�ddlm}|j
|j|j�|j
t��d��\}	}
|j
|	j|j�|j
|
j|j�dS)Nr)z/bin/catz/a/directory)rdZcommandr*cSsttj��dS)N)�IOErrorr�ZEISDIR)�enveloperrr�raise_eisdirszMSubprocessTests.test_spawn_fail_make_dispatchers_eisdir.<locals>.raise_eisdirr)r)rqcs
�j|�S)N)rr)rs)rtrrr_!szISubprocessTests.test_spawn_fail_make_dispatchers_eisdir.<locals>.<lambda>z2unknown error making dispatchers for 'cat': EISDIRzspawnerr: %srX)rrZmake_dispatchersrr!rrurmrvrqrwrxrnr&r7rirjr;r0r4rZryrzr{)rr-r,r�r8rrqror�r|r}r)rtr�'test_spawn_fail_make_dispatchers_eisdirs0
z7SubprocessTests.test_spawn_fail_make_dispatchers_eisdirc
s>t�}ttjtjtj��|_t|dd�}|j|�}ddl	m
}|j|_ddl
m}g�|j|j�fdd��|j�}|j|d�d}|j|j|�|j|jjdd	|�|jt|j�d
�|jt|j�d
�|j|j�|j|j�ddl	m
}|j|j|j�|jt��d��\}}	|j|j|j�|j|	j|j�dS)Nrz/good/filenamer)r)rqcs
�j|�S)N)rr)rs)rtrrr_:sz=SubprocessTests.test_spawn_fork_fail_eagain.<locals>.<lambda>z3Too many processes in process table to spawn 'good'zspawnerr: %s�rX)rr�r��EAGAINrar��fork_exceptionrrr!rrurmrvrqrwrxrnr&r7rirjrZ�parent_pipes_closed�child_pipes_closedr;r0r4ryrzr{)
rr-r,r8rrqror�r|r}r)rtr�test_spawn_fork_fail_eagain0s2
z+SubprocessTests.test_spawn_fork_fail_eagainc
s>t�}ttjtjtj��|_t|dd�}|j|�}ddl	m
}|j|_ddl
m}g�|j|j�fdd��|j�}|j|d�d}|j|j|�|j|jjdd	|�|jt|j�d
�|jt|j�d
�|j|j�|j|j�ddl	m
}|j|j|j�|jt��d��\}}	|j|j|j�|j|	j|j�dS)Nrz/good/filenamer)r)rqcs
�j|�S)N)rr)rs)rtrrr_Usz<SubprocessTests.test_spawn_fork_fail_other.<locals>.<lambda>z+unknown error during fork for 'good': EPERMzspawnerr: %sr�rX)rr�r�r�rar�r�rrr!rrurmrvrqrwrxrnr&r7rirjrZr�r�r;r0r4ryrzr{)
rr-r,r8rrqror�r|r}r)rtr�test_spawn_fork_fail_otherKs2
z*SubprocessTests.test_spawn_fork_fail_othercCs�t�}d|_t|dddd�}|j|�}|j�}|j|d�|j|jd�|j|jd�|j|jd�|jt	|j
�d�|jt	|j�|jd�|j|j
d�|j|jddgf�|j|jd�|j|jdd	i�dS)
Nrrz/good/filenamerC)�uidT�rXz*supervisor: child process was not spawned
)r�forkpidrrrnr&r�r��pgrp_setrZ�duped�
fds_closed�minfds�privsdropped�
execv_args�
execve_called�written)rr-r,r8rorrr�test_spawn_as_child_setuid_okfs"
z-SubprocessTests.test_spawn_as_child_setuid_okcCs�t�}d|_d|_t|dddd�}|j|�}|j�}|j|d�|j|jd�|j|jd�|j|j	d�|jt
|j�d�|jt
|j�|j
d�|j|jd	d
i�|j|jd�|j|jd�|j|jd�dS)
Nrzfailure reasonrz/good/filenamerC)r�Tr�rXz[supervisor: couldn't setuid to 1: failure reason
supervisor: child process was not spawned
F�)rr�Z
setuid_msgrrrnr&r�r�r�rZr�r�r�r�r�r��	_exitcode)rr-r,r8rorrr�test_spawn_as_child_setuid_fail|s"

z/SubprocessTests.test_spawn_as_child_setuid_failcCs�t�}d|_t|dddd�}|j|�}|j�}|j|d�|j|jd�|j|jd�|j|jd�|jt	|j
�d�|jt	|j�|jd�|j|j
ddgf�|j|jd�|j|jd�|j|jdd	i�dS)
Nrrz/good/filenamez/tmp)�	directoryTr�rXz*supervisor: child process was not spawned
)rr�rrrnr&r�r�r�rZr�r�r�r��changed_directoryr�r�)rr-r,r8rorrr�test_spawn_as_child_cwd_ok�s$
z*SubprocessTests.test_spawn_as_child_cwd_okcCs�t�}d|_t|dddd�}|j|�}|j�}|j|d�|j|jddgf�|j|jd�|j|jd�|j|j	ddi�dS)Nrrz/good/filenamerX)�umaskTz*supervisor: child process was not spawned
)
rr�rrrnr&r�Zumasksetr�r�)rr-r,r8rorrr�test_spawn_as_child_sets_umask�s
z.SubprocessTests.test_spawn_as_child_sets_umaskcCs�t�}d|_ttjtjtj��|_t|dddd�}|j	|�}|j
�}|j|d�|j|jd�|j|j
d�|j|jd�|jt|j�d�|jt|j�|jd�|j|jd�dd	i}|j|j|�|j|jd
�|j|jd�|j|jd�dS)Nrrz/good/filenamez/tmp)r�Tr�rXzUsupervisor: couldn't chdir to /tmp: ENOENT
supervisor: child process was not spawned
r�F)rr�r�r��ENOENTrar�Zchdir_exceptionrrrnr&r�r�r�rZr�r�r�r�r�r�r�r�)rr-r,r8ro�outrrr�test_spawn_as_child_cwd_fail�s(
z,SubprocessTests.test_spawn_as_child_cwd_failcCs�t�}d|_ttjtjtj��|_t|dd�}|j	|�}|j
�}|j|d�|j|jd�|j|j
d�|j|jd�|jt|j�d�|jt|j�|jd�ddi}|j|j|�|j|jd�|j|jd�dS)	Nrrz/good/filenameTr�rXzZsupervisor: couldn't exec /good/filename: EPERM
supervisor: child process was not spawned
r�)rr�r�r�r�rar��execv_exceptionrrrnr&r�r�r�rZr�r�r�r�r�r�)rr-r,r8ror�rrr�&test_spawn_as_child_execv_fail_oserror�s"
z6SubprocessTests.test_spawn_as_child_execv_fail_oserrorcCs�t�}d|_ttj�|_t|dd�}|j|�}|j�}|j	|d�|j	|j
d�|j	|jd�|j	|jd�|j	t
|j�d�|j	t
|j�|jd�|jd}d}|j|j|��|jd|k�|j	|jd�|j	|jd	�dS)
Nrrz/good/filenameTr�rXz)supervisor: couldn't exec /good/filename:�RuntimeErrorr�)rr�r�r�r�r�rrrnr&r�r�r�rZr�r�r�r�r;r<r�r�)rr-r,r8ror��headrrr�,test_spawn_as_child_execv_fail_runtime_error�s$

z<SubprocessTests.test_spawn_as_child_execv_fail_runtime_errorcCsht�}d|_t|ddddid�}|j|�}|j�}|j|d�|j|jddgf�|j|jdd�dS)Nrr)z/bin/catZ_TEST_�1)Zenvironment)rr�rrrnr&r��execv_environment)rr-r,r8rorrr�,test_spawn_as_child_uses_pconfig_environment�s
z<SubprocessTests.test_spawn_as_child_uses_pconfig_environmentcCs�t�}d|_t|dd�}|j|�}Gdd�d�}|�|_|�|j_|j�}|j|d�|j|jddgf�|j|j	dd�|j|j	dd�|j|j	d	d
�|j|j	dd�dS)
Nrr)z/bin/catc@seZdZdZdS)zQSubprocessTests.test_spawn_as_child_environment_supervisor_envvars.<locals>.Dummy�dummyN)�__name__�
__module__�__qualname__rdrrrr�Dummysr�ZSUPERVISOR_ENABLEDr�ZSUPERVISOR_PROCESS_NAMEZSUPERVISOR_GROUP_NAMEr�ZSUPERVISOR_SERVER_URLzhttp://localhost:9001)
rr�rr�groupr,rnr&r�r�)rr-r,r8r�rorrr�2test_spawn_as_child_environment_supervisor_envvarss&

zBSubprocessTests.test_spawn_as_child_environment_supervisor_envvarscCs�t�}d|_t|dddd�}d|_|j|�}|j�}|j|d�|j|jd�|j|jd�|j|j	d�|jt
|j�d�|jt
|j�|j
d�|j|jd�|j|jddgf�|j|jd�|j|jdd	i�dS)
Nrrz/good/filenamerC)r�TrXr�z*supervisor: child process was not spawned
)rr�r�redirect_stderrrrnr&r�r�r�rZr�r�r�r�r�r�r�)rr-r,r8rorrr�%test_spawn_as_child_stderr_redirecteds$
z5SubprocessTests.test_spawn_as_child_stderr_redirectedcCs,t�}d|_t|dd�}|j|�}|j�}|j|d�|j|jdjt�|j|jdjt�|j|jdjt�|j|j	dd�|j|j	dd�|j|j	d	d�|j|j
d�|jt|j�d
�|j|j
jdd�|j|jd�|j|j�|j|jjjd|�dd
lm}|j|j|j�dS)N�
rz/good/filename����stdin�stdout�stderrr�rzspawned: 'good' with pid 10)r)rr�rrrnr&r6ryrr5r�rZr�rirjr7r;r0r,r-�
pidhistoryr!rrm�STARTING)rr-r,r8rorrrr�test_spawn_as_parent/s(
z$SubprocessTests.test_spawn_as_parentcCs�t�}d|_t|dddd�}|j|�}|j�}|j|d�|j|jdjt�|j|jdjt�|j|j	dd�|j|j	d	d�|j|j	d
d�dS)Nr�rz/good/filenameT)r�r�r�r�r�r�)
rr�rrrnr&r6ryrr5)rr-r,r8rorrr�test_spawn_redirect_stderrEs
z*SubprocessTests.test_spawn_redirect_stderrcCs�d}t�}t|d|�}|j|�}dd}|jt|j|�d|_|j�|j|�|jd}|j	||j
|j�d|_|jt|j|�dS)	Nz/bin/cat�output�arC�
r�Ti )
rrrrJr��writer�rnr5r&r6Zinput_bufferr3)rr[r-r,r8�sent�stdin_fdrrr�
test_writeSs


zSubprocessTests.test_writecCsrd}t�}t|d|�}|j|�}dd}|jt|j|�d|_|j�|jd}|j	|j
�|jt|j|�dS)Nz/bin/catr�r�rCr�r�i )rrrrJr�r�r�rnr5r6�close)rr[r-r,r8r�r�rrr�test_write_dispatcher_closedbs

z,SubprocessTests.test_write_dispatcher_closedcCs�d}t�}t|d|�}|j|�}d|_|j�|jd}|j|j�d|jd<y|jd�|j	d�WnHt
k
r�}z,|j|jdt
j�|j|jdd�WYdd}~XnXdS)	Nz/bin/catr�rCr�rYznothing raisedrzProcess has no stdin channel)rrrr�rnr5r6r�r��failr�r&rRr��EPIPE)rr[r-r,r8r��excrrr�test_write_stdin_fd_noneos



z(SubprocessTests.test_write_stdin_fd_nonecCs�d}t�}t|d|�}|j|�}dd}|jt|j|�d|_|j�|jd}tt	j
tjt	j
��|j
|_|jt|j|�dS)Nz/bin/catr�r�rCr�r�i )rrrrJr�r�r�rnr5r�r�rar�r6Zflush_exception)rr[r-r,r8r�r�rrr�(test_write_dispatcher_flush_raises_epipe�s

z8SubprocessTests.test_write_dispatcher_flush_raises_epipecs�ddlm}�zxg��fdd�}tjtj|�|�}t�}t|d|�}|j|�}|j�}|jj	d}|j
|jd��|jt
|j�d�|j
|j�|j|j|�|j}	xNytjd�j�}
PWq�tk
r�}z|jdtjkr�WYdd}~Xq�Xq�Wtjd	�|j
|
jtt|	���dk�|jtj�}tjd	�|j|d�tjdtj�\}}
tjd�j�}
|j|
jtt|	���d
�|j �g�Wdytj!|�WnYnXtjtjtj"�XdS)Nr)�makeSpewcs�jd�dS)NT)rr)rR)�sigchldsrr�
sighandler�sz=SubprocessTests._dont_test_spawn_and_kill.<locals>.sighandlerZspewzspawned: 'spew' with pidr�Zpsg�������?rC���r�r�)#�supervisor.tests.baser��signal�SIGCHLDrrrrnrirjr;r<r&rZr5r/ra�popen�readr�rRr�ZEINTR�time�sleep�findrr:�kill�SIGTERM�waitpid�WNOHANG�assertNotEqual�remove�SIG_DFL)rr�r�r[r-r,r8ror�ZorigpidrjZwhyr/�stsr)r�r�_dont_test_spawn_and_kill�sJ


z)SubprocessTests._dont_test_spawn_and_killcCs�t�}t|dd�}|j|�}d|_tdd�}d|i|_ddlm}|j|_	t
j
�|_|j�|j
|j�|j|jd�|j
|j�|j|jjdd	�|j
|j�|j|jdtj�dS)
Nr@z/test�T)rBrYr)rz)killing test (pid 11) with signal SIGTERM)rrrr/rr6r!rrlrmr��laststopreport�stopr;r2r&r0rirjr3�killsr�r�)rr-r,r8�
dispatcherrrrr�	test_stop�s 



zSubprocessTests.test_stopcCs�t�}t|dd�}|j|�}d|_tdd�}d|i|_ddlm}|j|_	y|j
�|jd	�Wn4tk
r�}z|j
|jdd
�WYdd}~XnXdS)Nr@z/testr�T)rBrYr)rznothing raisedzCAssertion failed for test: STOPPED not in RUNNING STARTING STOPPING)rrrr/rr6r!r�STOPPEDrmr�r��AssertionErrorr&rR)rr-r,r8r�rr�rrr�&test_stop_not_in_stoppable_state_error�s


z6SubprocessTests.test_stop_not_in_stoppable_state_errorcCsjt�}t|dd�}|j|�}d|_tdd�}d|i|_ddlm}|j|_	|j
�|jt|j
j�d�dS)	Nr@z/testr�T)rBrYr)r)rrrr/rr6r!rr�rm�stop_reportr&rZrirj)rr-r,r8r�rrrr�3test_stop_report_logs_nothing_if_not_stopping_state�s


zCSubprocessTests.test_stop_report_logs_nothing_if_not_stopping_statecCs�t�}t|dd�}|j|�}d|_tdd�}d|i|_ddlm}|j|_	|j
|jd�|j�|j
t
|jj�d	�|j
|jjdd
�|j|jd�|j�|j
t
|jj�d	�dS)Nr@z/testr�T)rBrYr)rrCzwaiting for test to stop)rrrr/rr6r!r�STOPPINGrmr&r�r�rZrirjr�)rr-r,r8r�rrrr�1test_stop_report_logs_throttled_by_laststopreport�s


zASubprocessTests.test_stop_report_logs_throttled_by_laststopreportcCs�tj�d}t�}t|dd�}|j|�}d|_tdd�}d|i|_dd	lm}|j	|_
||_|j�|j
t|jj�d�|j|j|k�tjd
�|j�|j
t|jj�d�|j
|jjdd�|j|jd�|j�|j
t|jj�d�dS)
Nir@z/testr�T)rBrYr)rrXrCzwaiting for test to stop)r�rrrr/rr6r!rr�rmr�r�r&rZrirjr;r�r�)r�future_timer-r,r8r�rrrr�)test_stop_report_laststopreport_in_future�s(



z9SubprocessTests.test_stop_report_laststopreport_in_futurecs�t�}t|dd�}|j|�}g�ddlm}ddlm}|j|j�fdd��|j	|_
|j�|j|j
�|j|j�|j|j�|j|j
|j�|jt��d��d}|j|j|j�dS)	Nr@z/testr)r)rqcs
�j|�S)N)rr)rs)rtrrr_"sz.SubprocessTests.test_give_up.<locals>.<lambda>rC)rrrr!rrvrqrwrxrurmZgive_upr;�system_stopr1r0r4r&�FATALrZry�ProcessStateFatalEvent)rr-r,r8rrq�eventr)rtr�test_give_ups 
zSubprocessTests.test_give_upcCsLt�}t|dd�}|j|�}|jtj�|j|jjdd�|j	|j
�dS)Nr@z/testrz=attempted to kill test with sig SIGTERM but it wasn't running)rrrr�r�r�r&rirjr1r3)rr-r,r8rrr�test_kill_nopid-s
zSubprocessTests.test_kill_nopidcs�t�}t|dd�}|j|�}d|_g�ddlm}ddlm}|j|j	�fdd��|j
|_|jt
j�|j|jjdd	�|j|j�|j|jdt
j�|jt��d
��d}|j|j|j�dS)Nr@z/testr�r)r)rqcs
�j|�S)N)rr)rs)rtrrr_>sz9SubprocessTests.test_kill_from_starting.<locals>.<lambda>z)killing test (pid 11) with signal SIGTERMrC)rrrr/r!rrvrqrwrxr�rmr�r�r�r&rirjr;r3r�rZry�ProcessStateStoppingEvent)rr-r,r8rrqr�r)rtr�test_kill_from_starting6s 
z'SubprocessTests.test_kill_from_startingcs�t�}t|dd�}|j|�}d|_g�ddlm}ddlm}|j|j	�fdd��|j
|_|jt
j�|j|jjdd	�|j|j�|j|jdt
j�|jt��d
��d}|j|j|j�dS)Nr@z/testr�r)r)rqcs
�j|�S)N)rr)rs)rtrrr_Qsz8SubprocessTests.test_kill_from_running.<locals>.<lambda>z)killing test (pid 11) with signal SIGTERMrC)rrrr/r!rrvrqrwrxrlrmr�r�r�r&rirjr;r3r�rZryr�)rr-r,r8rrqr�r)rtr�test_kill_from_runningIs 
z&SubprocessTests.test_kill_from_runningcs.t�}t|dd�}ttjtjtj��|_|j|�}g�ddl	m
}ddlm}|j
|j�fdd��d|_|j|_|jtj�|j|jjdd	�|j|jjd
jd��|jd|jjd
k�|j|j�|j|jd�|j|j|j�|jt��d
��d}�d
}|j|j|j�|j|j|j �dS)Nr@z/testr)r)rqcs
�j|�S)N)rr)rs)rtrrr_esz>SubprocessTests.test_kill_from_running_error.<locals>.<lambda>r�z)killing test (pid 11) with signal SIGTERMrCzunknown problem killing test�	TracebackrX)!rrr�r�r�rar��kill_exceptionrr!rrvrqrwrxr/rlrmr�r�r�r&rirjr;r<r1r3�UNKNOWNrZryr��ProcessStateUnknownEvent)rr-r,r8rrqr|r}r)rtr�test_kill_from_running_error\s0
z,SubprocessTests.test_kill_from_running_errorcst�}t|dd�}ttjtjtj��|_|j|�}g�ddl	m
}ddlm}|j
|j�fdd��d|_|j|_|jtj�|j|jjdd	�|j|jjd
dt|j��|j|j�|j|jd�|j|j|j�|jt��d
��d}|j|j|j�dS)Nr@z/testr)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szDSubprocessTests.test_kill_from_running_error_ESRCH.<locals>.<lambda>r�z)killing test (pid 11) with signal SIGTERMrCzFunable to signal test (pid 11), it probably just exited on its own: %s)rrr�r��ESRCHrar�rrr!rrvrqrwrxr/rlrmr�r�r�r&rirj�strr;r3r�rZryr�)rr-r,r8rrqr|r)rtr�"test_kill_from_running_error_ESRCHws*
z2SubprocessTests.test_kill_from_running_error_ESRCHcs�t�}t|dd�}|j|�}d|_g�ddlm}ddlm}|j|j	�fdd��|j
|_|jt
j�|j|jjdd	�|j|j�|j|jdt
j�|j�g�dS)
Nr@z/testr�r)r)rqcs
�j|�S)N)rr)rs)rtrrr_�sz9SubprocessTests.test_kill_from_stopping.<locals>.<lambda>z)killing test (pid 11) with signal SIGKILL)rrrr/r!rrvrqrwrxr�rmr�r��SIGKILLr&rirjr;r3r�)rr-r,r8rrqr)rtr�test_kill_from_stopping�s
z'SubprocessTests.test_kill_from_stoppingcs�t�}t|dd�}|j|�}g�ddlm}ddlm}|j|j�fdd��|j	|_
|jtj
�|j|jjdd�|j|j��d}|j|j|j�dS)	Nr@z/testr)r)rqcs
�j|�S)N)rr)rs)rtrrr_�sz8SubprocessTests.test_kill_from_backoff.<locals>.<lambda>z2Attempted to kill test, which is in BACKOFF state.)rrrr!rrvrqrwrxrurmr�r�r	r&rirjr1r3ry�ProcessStateStoppedEvent)rr-r,r8rrqr�r)rtr�test_kill_from_backoff�s
z&SubprocessTests.test_kill_from_backoffcs�t�}t|dddd�}|j|�}d|_g�ddlm}ddlm}|j|j	�fd	d
��|j
|_|jt
j�|j|jjdd�|j|j�|j|jdt
j�|j�g�dS)
Nr@z/testT)Zkillasgroupr�r)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szGSubprocessTests.test_kill_from_stopping_w_killasgroup.<locals>.<lambda>z7killing test (pid 11) process group with signal SIGKILLi����)rrrr/r!rrvrqrwrxr�rmr�r�r	r&rirjr;r3r�)rr-r,r8rrqr)rtr�%test_kill_from_stopping_w_killasgroup�s
z5SubprocessTests.test_kill_from_stopping_w_killasgroupcs�t�}t|dddd�}|j|�}d|_g�ddlm}ddlm}|j|j	�fd	d
��|j
|_|jt
j�|j|jjdd�|j|j�|j|jdt
j�|jt��d��d}|j|j|j�|j|jdg�|j|j|j
�dS)Nr@z/testT)Zstopasgroupr�r)r)rqcs
�j|�S)N)rr)rs)rtrrr_�sz2SubprocessTests.test_stopasgroup.<locals>.<lambda>z7killing test (pid 11) process group with signal SIGTERMrCr/i����)r/r�)rrrr/r!rrvrqrwrxrlrmr�r�r�r&rirjr;r3r�rZryr��extra_values�
from_state)rr-r,r8rrqr�r)rtr�test_stopasgroup�s$
z SubprocessTests.test_stopasgroupcCsft�}t|dd�}|j|�}ddlm}|j|_|jtj�|j	|j
jdd�|j	t|j
�d�dS)Nr@z/testr)rz9attempted to send test sig SIGWINCH but it wasn't running)rrrr!rr�rmr��SIGWINCHr&rirjrZr�)rr-r,r8rrrr�test_signal_from_stopped�s
z(SubprocessTests.test_signal_from_stoppedcCs�t�}t|dd�}|j|�}d|_ddlm}|j|_|jtj	�|j
|jjdd�|j
t
|j�d�|j|j|jk�|j
|j|jtj	�dS)Nr@z/testr�r)rz"sending test (pid 11) sig SIGWINCHrC)rrrr/r!rrlrmr�rr&rirjrZr�r;)rr-r,r8rrrr�test_signal_from_running�s
z(SubprocessTests.test_signal_from_runningcs�t�}t|dd�}ttjtjtj��|_|j|�}g�ddl	m
}ddlm}|j
|j�fdd��d|_|j|_|jtj�|j|jjdd	�|j|jjd
dt|j��|j|j�|j|j|j�|j|jd�|jt��d�dS)Nr@z/testr)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szFSubprocessTests.test_signal_from_running_error_ESRCH.<locals>.<lambda>r�z"sending test (pid 11) sig SIGWINCHrCzJunable to signal test (pid 11), it probably just now exited on its own: %s)rrr�r�rrar�rrr!rrvrqrwrxr/rlrmr�rr&rirjrr1r3rZ)rr-r,r8rrqr)rtr�$test_signal_from_running_error_ESRCH�s(
z4SubprocessTests.test_signal_from_running_error_ESRCHcst�}t|dd�}ttjtjtj��|_|j|�}g�ddl	m
}ddlm}|j
|j�fdd��d|_|j|_|jtj�|j|jjdd	�|j|jjd
jd��|jd|jjd
k�|j|j�|j|j|j�|j|jd�|jt��d
��d}|j|j|j�dS)
Nr@z/testr)r)rqcs
�j|�S)N)rr)rs)rtrrr_s[email protected]_signal_from_running_error.<locals>.<lambda>r�z"sending test (pid 11) sig SIGWINCHrCz%unknown problem sending sig test (11)r)rrr�r�r�rar�rrr!rrvrqrwrxr/rlrmr�rr&rirjr;r<r1r3rrZryr)rr-r,r8rrqr�r)rtr�test_signal_from_running_errors.
z.SubprocessTests.test_signal_from_running_errorcsHt�}t|dddd�}|j|�}d|_||jjjd<d|_ddd	�}||_d
dl	m
}d
dlm}|j
|_g�|j|j�fd
d��d|_|jdd�|j|j�|j|jd
�|j|j|�|j|ji�|j|ji�|j|jjd
d�|j|jd�|jt��d��d
}|j|j|j�|j|jdg�|j|j|j
�dS)NrQz	/nottherez/tmp/foo)r*�{rCTrN)r�r�r)r)rqcs
�j|�S)N)rr)rs)rtrrr_-sz<SubprocessTests.test_finish_stopping_state.<locals>.<lambda>z(stopped: notthere (terminated by SIGHUP)r/)rrCr�)r/r)rrrZ
waitstatusr,r-r�r3r5r!rrvrqr�rmrwrxr/�finishr1r&r�r6rirj�
exitstatusrZryrrr)rr-r,r8r5rrqr�r)rtr�test_finish_stopping_states8

z*SubprocessTests.test_finish_stopping_statecsVt�}t|dddd�}|j|�}||jjjd<ddd�}||_dg|j_d	d
lm	}d	dl
m}|j|_
g�|j|j�fdd
��d|_|jdd�|j|j�|j|jd	�|j|j|�|j|ji�|j|ji�|j|jjd	d�|j|jd�|jt��d��d	}|j|j|j�|j|jd�|j|jddg�|j|j|j�dS)NrQz	/nottherez/tmp/foo)r*rrN)r�r�rCr)r)rqcs
�j|�S)N)rr)rs)rtrrr_KszISubprocessTests.test_finish_running_state_exit_expected.<locals>.<lambda>z1exited: notthere (terminated by SIGHUP; expected)T�expectedr/r�r�)rT)r/r) rrrr,r-r�r5�	exitcodesr!rrvrqrlrmrwrxr/rr1r3r&r�r6rirjrrZry�ProcessStateExitedEventrrr)rr-r,r8r5rrqr�r)rtr�'test_finish_running_state_exit_expected>s<


z7SubprocessTests.test_finish_running_state_exit_expectedcs�t�}t|dddd�}|j|�}||jjjd<ddd�}||_dg|j_tj�d	|_	d
dl
m}d
dlm
}|j|_g�|j|j�fd
d��d|_|jdd�|j|j�|j|jd
�|j|j|�|j|ji�|j|ji�|j|jjd
d�|j|jjdd�|j|jd�|jt��d��d
}|j|j|j�|j|jd�|j|j dg�|j|j!|j��d}|j|j|j"�|j|jd�|j|j ddg�|j|j!|j#�dS)NrQz	/nottherez/tmp/foo)r*rrN)r�r�rCir)r)rqcs
�j|�S)N)rr)rs)rtrrr_lszPSubprocessTests.test_finish_starting_state_laststart_in_future.<locals>.<lambda>z�process 'notthere' (123) laststart time is in the future, don't know how long process was running so assuming it did not exit too quicklyz1exited: notthere (terminated by SIGHUP; expected)rXTr/rr�r�)r/r)rT)r/r)$rrrr,r-r�r5rr�r.r!rrvrqr�rmrwrxr/rr1r3r&r�r6rirjrrZry�ProcessStateRunningEventrrrrrl)rr-r,r8r5rrqr�r)rtr�.test_finish_starting_state_laststart_in_future^sJ


z>SubprocessTests.test_finish_starting_state_laststart_in_futurecsBt�}t|ddddd�}|j|�}||jjjd<ddd�}||_dg|j_tj�|_	d
dl
m}d
dlm
}|j|_g�|j|j�fd
d��d|_|jdd	�|j|j�|j|jd
�|j|j|�|j|ji�|j|ji�|j|jjd
d�|j|jd�|jt��d	��d
}|j|j|j�|j|j|j�dS)NrQz	/nottherez/tmp/foor�)r*�	startsecsrrN)r�r�rCr)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szOSubprocessTests.test_finish_starting_state_exited_too_quickly.<locals>.<lambda>z5exited: notthere (terminated by SIGHUP; not expected)r�) rrrr,r-r�r5rr�r.r!rrvrqr�rmrwrxr/rr1r3r&r�r6rirjrrZryr{r)rr-r,r8r5rrqr�r)rtr�-test_finish_starting_state_exited_too_quickly�s8




z=SubprocessTests.test_finish_starting_state_exited_too_quicklycsbt�}t|ddddd�}|j|�}||jjjd<ddd�}||_dg|j_tj�|_	d
dl
m}d
dlm
}|j|_g�|j|j�fd
d��d|_|jdd	�|j|j�|j|jd
�|j|j|�|j|ji�|j|ji�|j|jjd
d�|j|jd�|jt��d	��d
}|j|j|j�|j|jd�|j|j ddg�|j|j!|j�dS)NrQz	/nottherez/tmp/foor�)r*r rrN)r�r�rCr)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szdSubprocessTests.test_finish_running_state_exited_too_quickly_due_to_clock_rollback.<locals>.<lambda>z1exited: notthere (terminated by SIGHUP; expected)Trr/r�r�)rT)r/r)"rrrr,r-r�r5rr�r.r!rrvrqrlrmrwrxr/rr1r3r&r�r6rirjrrZryrrrr)rr-r,r8r5rrqr�r)rtr�Btest_finish_running_state_exited_too_quickly_due_to_clock_rollback�s>




zRSubprocessTests.test_finish_running_state_exited_too_quickly_due_to_clock_rollbackcsxt�}t|dddd�}|j|�}||jjjd<ddd�}||_dg|j_tj�d	|_	d
dl
m}d
dlm
}|j|_g�|j|j�fd
d��d|_|jdd�|j|j�|j|jd
�|j|j|�|j|ji�|j|ji�|j|jjd
d�|j|jjdd�|j|jd�|jt��d��d
}|j|j|j�|j|jd�|j|j ddg�|j|j!|j�dS)NrQz	/nottherez/tmp/foo)r*rrN)r�r�rCir)r)rqcs
�j|�S)N)rr)rs)rtrrr_�szOSubprocessTests.test_finish_running_state_laststart_in_future.<locals>.<lambda>z�process 'notthere' (123) laststart time is in the future, don't know how long process was running so assuming it did not exit too quicklyz1exited: notthere (terminated by SIGHUP; expected)Trr/r�r�)rT)r/r)"rrrr,r-r�r5rr�r.r!rrvrqrlrmrwrxr/rr1r3r&r�r6rirjrrZryrrrr)rr-r,r8r5rrqr�r)rtr�-test_finish_running_state_laststart_in_future�sB


z=SubprocessTests.test_finish_running_state_laststart_in_futurec	s�ddlm}g�|j|j�fdd��|j|j�fdd��t�}t|dddd	d
�}|j|�}ddlm	}|j
|_t�}||_
|jdd
�|jt��d��\}}|j|j|j�|j|j|j�|j|j|�|j|j
|�|j|j
d�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�szOSubprocessTests.test_finish_with_current_event_sends_rejected.<locals>.<lambda>cs
�j|�S)N)rr)rs)rtrrr_�srQz	/nottherez/tmp/foor�)r*r )rrrCrX)rvrqrwrx�EventRejectedEventrrrr!rrlrmrr�rr&rZryr�process)	rrqr-r,r8rr�r|r}r)rtr�-test_finish_with_current_event_sends_rejected�s*

z=SubprocessTests.test_finish_with_current_event_sends_rejectedcCs6t�}t|dd�}|j|�}|j�|j|jd�dS)Nr@z/test)rrr�set_uidr&r�)rr-r,r8rrr�test_set_uid_no_uids

z#SubprocessTests.test_set_uid_no_uidcCsFt�}t|dddd�}|j|�}|j�}|j|jd�|j|d�dS)Nr@z/testrC)r�)rrrr'r&r�)rr-r,r8r�rrr�test_set_uid
s
zSubprocessTests.test_set_uidcCs�t�}t|ddddd�}|j|�}t|ddddd�}|j|�}t|dddd	d�}|j|�}|||g}|j�|j||||g�dS)
NrQz	/nottherez/tmp/foorC)r*�priorityZ	notthere1rXZ	notthere2r�)rrr�sortr&)rr-r,r8Z	instance1Z	instance2rtrrr�test_cmp_byprioritys 



z#SubprocessTests.test_cmp_byprioritycs�ddlm}g�|j|j�fdd��ddlm}m}t�}|j|_	t
|ddd�}|j|�}d|_|j
|_|j�|j|j|j
�|j�g�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_.szYSubprocessTests.test_transition_stopped_to_starting_supervisor_stopping.<locals>.<lambda>)r�SupervisorStatesr%z/bin/process)rvrqrwrxr!rr-r�SHUTDOWN�moodrrr.r�rm�
transitionr&)rrqrr-r-�pconfigr%r)rtr�7test_transition_stopped_to_starting_supervisor_stopping+s
zGSubprocessTests.test_transition_stopped_to_starting_supervisor_stoppingcs�ddlm}g�|j|j�fdd��ddlm}m}t�}|j|_	t
|ddd�}|j|�}d|_|j
|_|j�|j|j|j�|jt��d��d}|j|j|j�dS)	Nr)rqcs
�j|�S)N)rr)rs)rtrrr_?szXSubprocessTests.test_transition_stopped_to_starting_supervisor_running.<locals>.<lambda>)rr-r%z/bin/processrC)rvrqrwrxr!rr-rrlr/rrr.r�rmr0r&r�rZryrz)rrqrr-r-r1r%r�r)rtr�6test_transition_stopped_to_starting_supervisor_running<s
zFSubprocessTests.test_transition_stopped_to_starting_supervisor_runningcs�ddlm}g�|j|j�fdd��ddlm}m}t�}|j|_	t
|ddd�}ddlm}||_
|j|�}d	|_d
|_|j|_|j�|j|j|j�|j|j�|j�g�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_QszXSubprocessTests.test_transition_exited_to_starting_supervisor_stopping.<locals>.<lambda>)rr-r%z/bin/process)�RestartUnconditionallyrCT)rvrqrwrxr!rr-rr.r/r�supervisor.datatypesr4�autorestartrr.r��EXITEDrmr0r&r;)rrqrr-r-r1r4r%r)rtr�6test_transition_exited_to_starting_supervisor_stoppingNs"
zFSubprocessTests.test_transition_exited_to_starting_supervisor_stoppingcs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}ddlm	}||_
|j|�}d	|_|j
|_|j�|j|j|j�|jt��d	��d}|j|j|j�dS)
Nr)rqcs
�j|�S)N)rr)rs)rtrrr_fsz^SubprocessTests.test_transition_exited_to_starting_uncond_supervisor_running.<locals>.<lambda>)rr%z/bin/process)r4rC)rvrqrwrxr!rrrr5r4r6rr.r7rmr0r&r�rZryrz)rrqrr-r1r4r%r�r)rtr�<test_transition_exited_to_starting_uncond_supervisor_runningcs 
zLSubprocessTests.test_transition_exited_to_starting_uncond_supervisor_runningcs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}ddlm	}||_
|j|�}d	|_|j
|_d
|_|j�|j|j|j�|jt��d	��d}|j|j|j�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_ysz^SubprocessTests.test_transition_exited_to_starting_condit_supervisor_running.<locals>.<lambda>)rr%z/bin/process)�RestartWhenExitUnexpectedrCZbogus)rvrqrwrxr!rrrr5r:r6rr.r7rmrr0r&r�rZryrz)rrqrr-r1r:r%r�r)rtr�<test_transition_exited_to_starting_condit_supervisor_runningvs"
zLSubprocessTests.test_transition_exited_to_starting_condit_supervisor_runningcs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}ddlm	}||_
|j|�}d	|_|j
|_d|_|j�|j|j|j
�|j�g�dS)
Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�szbSubprocessTests.test_transition_exited_to_starting_condit_fls_supervisor_running.<locals>.<lambda>)rr%z/bin/process)r:rC)rvrqrwrxr!rrrr5r:r6rr.r7rmrr0r&)rrqrr-r1r:r%r)rtr�@test_transition_exited_to_starting_condit_fls_supervisor_running�s
zPSubprocessTests.test_transition_exited_to_starting_condit_fls_supervisor_runningcs�ddlm}g�|j|j�fdd��ddlm}m}t�}|j|_	t
|ddd�}|j|�}d|_d|_
d|_|j|_|j�|j|j|j�|j�g�dS)	Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�szYSubprocessTests.test_transition_backoff_to_starting_supervisor_stopping.<locals>.<lambda>)rr-r%z/bin/processrC)rvrqrwrxr!rr-rr.r/rrr.r0r4rurmr0r&)rrqrr-r-r1r%r)rtr�7test_transition_backoff_to_starting_supervisor_stopping�s
zGSubprocessTests.test_transition_backoff_to_starting_supervisor_stoppingcs�ddlm}g�|j|j�fdd��ddlm}m}t�}|j|_	t
|ddd�}|j|�}d|_d|_
d|_|j|_|j�|j|j|j�|jt��d�|j�dj|j�dS)	Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�szXSubprocessTests.test_transition_backoff_to_starting_supervisor_running.<locals>.<lambda>)rr-r%z/bin/processrC)rvrqrwrxr!rr-rrlr/rrr.r0r4rurmr0r&r�rZryrz)rrqrr-r-r1r%r)rtr�6test_transition_backoff_to_starting_supervisor_running�s 
zFSubprocessTests.test_transition_backoff_to_starting_supervisor_runningcs�ddlm}g�|j|j�fdd��ddlm}m}t�}|j|_	t
|ddd�}|j|�}d|_t
|_d|_|j|_|j�|j|j|j�|j�g�dS)	Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�sz_SubprocessTests.test_transition_backoff_to_starting_supervisor_running_notyet.<locals>.<lambda>)rr-r%z/bin/processrC)rvrqrwrxr!rr-rrlr/rrr.rr0r4rurmr0r&)rrqrr-r-r1r%r)rtr�=test_transition_backoff_to_starting_supervisor_running_notyet�s
zMSubprocessTests.test_transition_backoff_to_starting_supervisor_running_notyetcs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}|j|�}d|_	d|_
d	|_d|_d|_
d
|_d|_|j|_|j�|j|j	d�|j|j
d�|j|j�|j|jjdd�|jt��d��d}|j|j|j�dS)
Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�szESubprocessTests.test_transition_starting_to_running.<locals>.<lambda>)rr%z/bin/processrCF�abc�defz_success: process entered RUNNING state, process has stayed up for > than 10 seconds (startsecs))rvrqrwrxr!rrrrr4r0r�r.r/�
stdout_buffer�
stderr_bufferr�rmr0r&r1rirjrZryr)rrqrr-r1r%r�r)rtr�#test_transition_starting_to_running�s0
z3SubprocessTests.test_transition_starting_to_runningc	sRddlm}g�|j|j�fdd��ddlm}tj�d}t�}d}t|ddd	|d
�}|j	|�}d|_
d|_d|_||_
d|_d
|_d|_|j|_|j�|j|j|j�|j|j
|k�tj|d�|j�|j|j
d�|j|jd�|j|j�|j|j|j�|j|jjddj|��|jt��d��d}|j|j|j�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_�szYSubprocessTests.test_transition_starting_to_running_laststart_in_future.<locals>.<lambda>)rirXr%z/bin/process)r rCFr@rAz_success: process entered RUNNING state, process has stayed up for > than {} seconds (startsecs))rvrqrwrxr!rr�rrrr4r0r�r.r/rBrCr�rmr0r&r;r�r1rlrirj�formatrZryr)	rrqrr�r-Ztest_startsecsr1r%r�r)rtr�7test_transition_starting_to_running_laststart_in_future�sB

zGSubprocessTests.test_transition_starting_to_running_laststart_in_futurecs�ddlm}g�|j|j�fdd��ddlm}tj�d}t�}t|ddd�}|j	|�}d	|_
||_d|_|j
|_|j�|j|j|j
�|j|j|k�|j�|j|j|j�|jt��d	�|j�dj|j�dS)
Nr)rqcs
�j|�S)N)rr)rs)rtrrr_*szUSubprocessTests.test_transition_backoff_to_starting_delay_in_future.<locals>.<lambda>)rir%z/bin/processrC)rvrqrwrxr!rr�rrrr.r0r4rurmr0r&r;r�rZryrz)rrqrr�r-r1r%r)rtr�3test_transition_backoff_to_starting_delay_in_future's&
zCSubprocessTests.test_transition_backoff_to_starting_delay_in_futurecs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}|j|�}d|_	d	|_
d|_d
|_d|_
d|_|j|_|j�|j|j
d�|j|jd�|j|j�|j|jjdd
�|jt��d��d}|j|j|j�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_LszBSubprocessTests.test_transition_backoff_to_fatal.<locals>.<lambda>)rr%z/bin/processrCi'Fr@rAzHgave up: process entered FATAL state, too many start retries too quickly)rvrqrwrxr!rrrrr.r4r0r�rBrCrurmr0r&r;rirjrZryr�)rrqrr-r1r%r�r)rtr� test_transition_backoff_to_fatalIs.
z0SubprocessTests.test_transition_backoff_to_fatalcs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}|j|�}t	|_
|j|_|j
�|j|j|j�|j�g�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_kszISubprocessTests.test_transition_stops_unkillable_notyet.<locals>.<lambda>)rr%z/bin/process)rvrqrwrxr!rrrrrr0r�rmr0r&)rrqrr-r1r%r)rtr�'test_transition_stops_unkillable_notyeths
z7SubprocessTests.test_transition_stops_unkillable_notyetcs�ddlm}g�|j|j�fdd��ddlm}t�}t|ddd�}|j|�}d|_	d|_
d	|_|j|_
|j�|j|j�|j|j	d�|j|j
|j�|j|jjdd
�|j|jdtj�|j�g�dS)Nr)rqcs
�j|�S)N)rr)rs)rtrrr_{szBSubprocessTests.test_transition_stops_unkillable.<locals>.<lambda>)rr%z/bin/processrCFz"killing 'process' (1) with SIGKILL)rvrqrwrxr!rrrrr0r/r3r�rmr0r;r�r&rirjr�r�r	)rrqrr-r1r%r)rtr� test_transition_stops_unkillablexs&
z0SubprocessTests.test_transition_stops_unkillablecCs8t�}t|dd�}|j|�}d|_|j|jd�d�dS)Nr@z/testr�F)rrrrmr&�change_state)rr-r,r8rrr�2test_change_state_doesnt_notify_if_no_state_change�s

zBSubprocessTests.test_change_state_doesnt_notify_if_no_state_changecCs\ddlm}t�}t|dd�}|j|�}d|_|j|j�|j|j	d�|j
|jdk�dS)Nr)rr@z/testr�rC)r!rrrrrmrKrur&r4r;r0)rrr-r,r8rrr�(test_change_state_sets_backoff_and_delay�s
z8SubprocessTests.test_change_state_sets_backoff_and_delayN)]r�r�r�rrrr(r9r?rFrHrIrLrOrPrSrTrUrVr\r]rhrkrpr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
rr
rrrrrrrrr!r"r#r&r(r)r,r2r3r8r9r;r<r=r>r?rDrFrGrHrIrJrLrMrrrrrs�




+"	
 )"!% 4"rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zej
edeejd��dd��Zej
edeejd��dd��Zej
ededd��dd��ZdS)�FastCGISubprocessTestscCsddlm}|S)Nr)�FastCGISubprocess)rrO)rrOrrrr�sz&FastCGISubprocessTests._getTargetClasscOs|j�||�S)N)r)rrrrrrr�szFastCGISubprocessTests._makeOnecCsddlm}|�dS)Nr)r)rr)rrrrrr�szFastCGISubprocessTests.tearDowncCs8t�}d|_t|dddd�}|j|�}|jt|j�dS)Nrrz/good/filenamerC)r�)rr�rrrJ�NotImplementedErrorrn)rr-r,r8rrr�
test_no_group�s

z$FastCGISubprocessTests.test_no_groupcCsFt�}d|_t|dddd�}|j|�}tt|��|_|jt|j	�dS)Nrrz/good/filenamerC)r�)
rr�rrrr
r�rJrPrn)rr-r,r8rrr�test_no_socket_manager�s
z-FastCGISubprocessTests.test_no_socket_managercCs�t�}d|_t|dddd�}|j|�}td�}t|ddd|�}t|�|_|j�}|j	|d�|j	t
|j�d	�|j	|jdd�|j	|j|jd
d�|j	|j|jdd�|j	t
|j
�|jd	�dS)
Nrrz/good/filenamerC)r�r��whateveri�r�Zchild_stdoutZchild_stderrrX)rr�rrrr
rr�rnr&rZr�r5r�r�)rr-r,r8�sock_config�gconfigrorrr�test_prepare_child_fds�s


z-FastCGISubprocessTests.test_prepare_child_fdscCs�t�}d|_t|dddd�}d|_|j|�}td�}t|dd	d|�}t|�|_|j	�}|j
|d�|j
t|j�d
�|j
|jdd�|j
t|j
�|jd�dS)Nrrz/good/filenamerC)r�Tr�rSi�rXr�)rr�rr�rrr
rr�rnr&rZr�r�r�)rr-r,r8rTrUrorrr�(test_prepare_child_fds_stderr_redirected�s


z?FastCGISubprocessTests.test_prepare_child_fds_stderr_redirectedcCsnt�}t|dddd�}|j|�}td�}t|ddd|�}t|�|_|j|jdk�|j	�|j
|jdk�dS)Nrz/good/filenamerC)r�r�rSi�)rrrrr
rr�r;�	fcgi_sock�before_spawnr1)rr-r,r8rTrUrrr�!test_before_spawn_gets_socket_ref�s


z8FastCGISubprocessTests.test_before_spawn_gets_socket_refcCsBt�}t|dddd�}|j|�}d|_|j�|j|jdk�dS)Nrz/good/filenamerC)r�Zhello)rrrrX�after_finishr;)rr-r,r8rrr�$test_after_finish_removes_socket_ref�s
z;FastCGISubprocessTests.test_after_finish_removes_socket_refr)Zreturn_valuecCs�t�}t|dddd�}|j|�}t�|_|jtjtj�}|j	tj
|d�|j	d|jjd�tj}|j	d|jd�|j
dd}|j
dd	}|j	tj|d
�|j	tj|d�dS)Nrz/good/filenamerC)r�z3FastCGISubprocess.finish() did not pass thru resultz0FastCGISubprocess.after_finish() not called oncez#Subprocess.finish() not called oncerrXz*Subprocess.finish() pid arg was not passedz*Subprocess.finish() sts arg was not passed)rrrrr[rrr/r�r&�
finish_result�
call_countr�	call_args)rr-r,r8roZfinish_mockZpid_argZsts_argrrr�test_finish_override�s$




z+FastCGISubprocessTests.test_finish_overriderncCslt�}t|dddd�}|j|�}t�|_|j�}|jtj|d�|jd|jj	d�t
j}|jd|j	d�dS)Nrz/good/filenamerC)r�z2FastCGISubprocess.spawn() did not pass thru resultz0FastCGISubprocess.before_spawn() not called oncez"Subprocess.spawn() not called once)rrrrrYrnr&r�ppidr^r)rr-r,r8roZ
spawn_mockrrr�test_spawn_override_successs


z2FastCGISubprocessTests.test_spawn_override_successNcCsjt�}t|dddd�}|j|�}t�|_d|_|j�}|jd|d�|jd|jjd�|jd|jd�dS)	Nrz/good/filenamerC)r�znuke me on errorz2FastCGISubprocess.spawn() did return None on errorz0FastCGISubprocess.before_spawn() not called oncez:FastCGISubprocess.spawn() did not remove sock ref on error)	rrrrrYrXrnr&r^)rr-r,r8rorrr�test_spawn_errors

z'FastCGISubprocessTests.test_spawn_error)r�r�r�rrrrQrRrVrWrZr\r�objectrrrr]r`rarbrcrrrrrN�s	rNc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ProcessGroupBaseTestscCsddlm}|S)Nr)�ProcessGroupBase)rrf)rrfrrrr'sz%ProcessGroupBaseTests._getTargetClasscOs|j�||�S)N)r)rrRrrrrr+szProcessGroupBaseTests._makeOnecCsjt�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_|j	�}|j
||g�dS)Nr)r�process1z
/bin/process1)rm)�pconfigs)rr!rrr	r�r
r�	processesZget_unstopped_processesr&)rr-r�pconfig1rgrUr�Z	unstoppedrrr�test_get_unstopped_processes.s

z2ProcessGroupBaseTests.test_get_unstopped_processescCs\t�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_|j	�dS)Nr)rrgz
/bin/process1)rm)rh)
rr!rrr	r�r
rri�
before_remove)rr-rrjrgrUr�rrr�test_before_remove9s

z(ProcessGroupBaseTests.test_before_removec
Csddlm}t�}t|ddd�}t||jd�}t|ddd�}t||jd�}t|ddd	�}t||jd�}t|d
d
d�}	t|	|jd�}
d|
_	d
|
_
t|||||	gd�}|j|�}||||
d�|_
|j�|j|jd�|j|jd�|j|jd�|j|
jd�|j|
j|j�dS)Nr)rrgz
/bin/process1)rm�process2z
/bin/process2�process3z
/bin/process3�process4z
/bin/process4i�r�)rh)rgrnrorpFT)r!rrrr	r�rlr�rur0r4r
rriZstop_allr&Zstop_calledrmr�)
rrr-rjrg�pconfig2rnZpconfig3roZpconfig4rprUr�rrr�
test_stop_allCs0
z#ProcessGroupBaseTests.test_stop_allc
Cs�t�}ddlm}t|ddd�}t||jd�}ddi|_t|ddd�}t||jd�}d	di|_t|||gd
�}|j|�}||d�|_	|j
�}	|j|	ddd��dS)
Nr)rrgz
/bin/process1)rmr�rnz
/bin/process2r�)rh)rgrn)r�r�)rr!rrr	r�r6r
rriZget_dispatchersr&)
rr-rrjrgrqrnrUr�rorrr�test_get_dispatchersas


z*ProcessGroupBaseTests.test_get_dispatcherscCsjt�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_|j	�|j
|jd�dS)Nr)rrgz
/bin/process1)rm)rhT)rr!rrr	r�r
rrirDr&rE)rr-rrjrgrUr�rrrrFps

z%ProcessGroupBaseTests.test_reopenlogscCsjt�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_|j	�|j
|jd�dS)Nr)rrgz
/bin/process1)rm)rhT)rr!rrr	r�r
rrirGr&Zlogsremoved)rr-rrjrgrUr�rrrrH{s

z%ProcessGroupBaseTests.test_removelogsc	Cs�t�}t|�}|j|�}t|�}|j|�}t|�}|j|�}d|j_d|j_d|j_||g}|j�|j|||g�|j||�|j||�dS)Nr�rC)rr
rr,r*r+r&r�)	rr-Zgconfig1Zgroup1Zgconfig2Zgroup2Zconfig3Zgroup3rtrrr�test_ordering_and_comparison�s


z2ProcessGroupBaseTests.test_ordering_and_comparisonN)r�r�r�rrrkrmrrrsrFrHrtrrrrre&s
rec@s$eZdZdd�Zdd�Zdd�ZdS)�ProcessGroupTestscCsddlm}|S)Nr)�ProcessGroup)rrv)rrvrrrr�sz!ProcessGroupTests._getTargetClasscCsDt�}t|�}|j|�}t|�}|jd|k�|j|jd�|�dS)Nzsupervisor.process.ProcessGroupznamed whatever>)rr
rr:r;r=)rr-rUr�r>rrrr?�s
zProcessGroupTests.test_reprcCsjt�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_|j	�|j
|jd�dS)Nr)rrgz
/bin/process1)rm)rhT)rr!rrr	r�r
rrir0r&�transitioned)rr-rrjrgrUr�rrr�test_transition�s

z!ProcessGroupTests.test_transitionN)r�r�r�rr?rxrrrrru�sruc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�FastCGIProcessGroupTestscCsddlm}|S)Nr)�FastCGIProcessGroup)rrz)rrzrrrr�sz(FastCGIProcessGroupTests._getTargetClasscKs|j�}||f|�S)N)r)rr,�kwargs�clsrrrr�sz!FastCGIProcessGroupTests._makeOnecCs6t�}t|�}d|_Gdd�dt�}|j||d�dS)Nc@seZdZdd�Zdd�ZdS)zVFastCGIProcessGroupTests.test___init__without_socket_error.<locals>.DummySocketManagercSsdS)Nr)rr,rirrr�__init__�sz_FastCGIProcessGroupTests.test___init__without_socket_error.<locals>.DummySocketManager.__init__cSsdS)Nr)rrrr�
get_socket�szaFastCGIProcessGroupTests.test___init__without_socket_error.<locals>.DummySocketManager.get_socketN)r�r�r�r}r~rrrr�DummySocketManager�sr)�
socketManager)rr
�
socket_configrdr)rr-rUrrrr�!test___init__without_socket_error�s
z:FastCGIProcessGroupTests.test___init__without_socket_errorcCs<t�}t|�}d|_Gdd�dt�}|jt|j||d�dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)zSFastCGIProcessGroupTests.test___init__with_socket_error.<locals>.DummySocketManagercSsdS)Nr)rr,rirrrr}�sz\FastCGIProcessGroupTests.test___init__with_socket_error.<locals>.DummySocketManager.__init__cSstd��dS)Nr�)�KeyError)rrrrr~�sz^FastCGIProcessGroupTests.test___init__with_socket_error.<locals>.DummySocketManager.get_socketcSsdS)Nr,r)rrrrr,�szZFastCGIProcessGroupTests.test___init__with_socket_error.<locals>.DummySocketManager.configN)r�r�r�r}r~r,rrrrr�sr)r�)rr
r�rdrJ�
ValueErrorr)rr-rUrrrr�test___init__with_socket_error�sz7FastCGIProcessGroupTests.test___init__with_socket_errorN)r�r�r�rrr�r�rrrrry�s
ryc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S)(�EventListenerPoolTestscCsddlm}|�dS)Nr)r)rr)rrrrr�setUp�szEventListenerPoolTests.setUpcCsddlm}|�dS)Nr)r)rr)rrrrrr�szEventListenerPoolTests.tearDowncCsddlm}|S)Nr)�EventListenerPool)rr�)rr�rrrr�sz&EventListenerPoolTests._getTargetClasscCs�t�}t|�}Gdd�d�}|f|_|j|�}ddlm}|jt|j�d�|j|jd||j	f�|j|jd|j
|jf�|j|jd�dS)Nc@seZdZdS)z3EventListenerPoolTests.test_ctor.<locals>.EventTypeN)r�r�r�rrrr�	EventType�sr�r)rqrXrCr�)
rr
�pool_eventsrrvrqr&rZ�	callbacks�_acceptEventr$�handle_rejected�serial)rr-rUr��poolrqrrrr9�s
z EventListenerPoolTests.test_ctorcCsjt�}t|�}Gdd�d�}|f|_|j|�}ddlm}|jt|j�d�|j	�|jt|j�d�dS)Nc@seZdZdS)zUEventListenerPoolTests.test_before_remove_unsubscribes_from_events.<locals>.EventTypeN)r�r�r�rrrrr��sr�r)rqrX)
rr
r�rrvrqr&rZr�rl)rr-rUr�r�rqrrr�+test_before_remove_unsubscribes_from_events�s
zBEventListenerPoolTests.test_before_remove_unsubscribes_from_eventsc	Cs�t�}d|_t|�}d|_|j|�}ddlm}|j|jj	ddd�}|j
dd	�\}}|j
�}|j|dd
�|j|d	d�|j|dd
�|j|dd�|j|dd�|j|dd�|j|dd�|j|d�dS)NZthesupervisornameZthepoolnamer)rq�P�zpayload
�
rCzver:3.0zserver:thesupervisornamerXz	serial:80r�zpool:thepoolnamer�z
poolserial:20r�z&eventname:PROCESS_COMMUNICATION_STDOUTr�zlen:8)rZ
identifierr
rdrrvrqZ_eventEnvelopeZ
EventTypesZPROCESS_COMMUNICATION_STDOUTrcr&)	rr-rUr�rqro�header�payloadZheadersrrr�test__eventEnvelope�s$
z*EventListenerPoolTests.test__eventEnvelopecs�t�}t|�}t|ddd�}t|��t||gd�}|j|�}d�i|_ddg|_Gdd�d��G��fdd�d�}|�}d|_|j|�|j	|j|j
ddg�dS)	Nrgz
/bin/process1)rhc@seZdZdZdS)zLEventListenerPoolTests.test_handle_rejected_no_overflow.<locals>.DummyEvent1r@N)r�r�r�r�rrrr�DummyEvent1sr�cseZdZ�Z��ZdS)zLEventListenerPoolTests.test_handle_rejected_no_overflow.<locals>.DummyEvent2N)r�r�r�r%r�r)r�rgrr�DummyEvent2sr�rC)rr
rr	rri�event_bufferr�r�r&r�)rr-rUrjr�r�Z
dummyeventr)r�rgr� test_handle_rejected_no_overflows



z7EventListenerPoolTests.test_handle_rejected_no_overflowcs�t�}t|�}t|ddd�}t|��t||gd�}d|_|j|�}d�i|_Gdd�d��G��fdd�d�}�d	�}�d
�}�d�}|d�}	|||g|_|j|	�d
d�|jD�}
|j	|
dd
dg�|j	|j
jjj
dd�dS)Nrgz
/bin/process1)rhr�c@seZdZdd�ZdS)zWEventListenerPoolTests.test_handle_rejected_event_buffer_overflowed.<locals>.DummyEventcSs
||_dS)N)r�)rr�rrrr}/sz`EventListenerPoolTests.test_handle_rejected_event_buffer_overflowed.<locals>.DummyEvent.__init__N)r�r�r�r}rrrrr.srcseZdZ��fdd�ZdS)z_EventListenerPoolTests.test_handle_rejected_event_buffer_overflowed.<locals>.DummyRejectedEventcs�|_�|�|_dS)N)r%r�)rr�)rrgrrr}2szhEventListenerPoolTests.test_handle_rejected_event_buffer_overflowed.<locals>.DummyRejectedEvent.__init__N)r�r�r�r}r)rrgrr�DummyRejectedEvent1sr�r��b�cZrejectedcSsg|]
}|j�qSr)r�)�.0rsrrr�
<listcomp>;szWEventListenerPoolTests.test_handle_rejected_event_buffer_overflowed.<locals>.<listcomp>rz9pool whatever event buffer overflowed, discarding event a)rr
rr	�buffer_sizerrir�r�r&r,r-rirj)rr-rUrjr�r�Zevent_aZevent_bZevent_cZ	rej_eventZserialsr)rrgr�,test_handle_rejected_event_buffer_overflowed%s(


zCEventListenerPoolTests.test_handle_rejected_event_buffer_overflowedcCs�t�}t|�}t|ddd�}ddlm}t||gd�}|j|�}|jd}ttj	t
jtj	��|_|j
|_t�}|j|�|j�|j|j|j
�|j|j|g�|j|jjdd�|j|jjdd�dS)	Nrgz
/bin/process1r)�EventListenerStates)rhzUepipe occurred while sending event abc to listener process1, listener state unchangedrCz<rebuffering event abc for pool whatever (buf size=0, max=10))rr
rr!r�rrir�r�r�rar�Zwrite_exception�READY�listener_staterr��dispatchr&r�rirj)rr-rUrjr�r�rgr�rrr�test_dispatch_pipe_errorAs&


z/EventListenerPoolTests.test_dispatch_pipe_errorc	Cs�ddlm}t�}t|�}t|ddd�}t||gd�}|j|�}|jd}ddlm}|j	|_
td�}|j|�|j
|j|j�|j
|jd|j�dS)Nr)�GlobalSerialrgz
/bin/process1)rh)r�rS)rr�rr
rrrir!r�r�r�rr�r&r�Zpool_serials)	rr�r-rUrjr�rgr�r�rrr�1test__acceptEvent_attaches_pool_serial_and_serialWs


zHEventListenerPoolTests.test__acceptEvent_attaches_pool_serial_and_serialcCsBt�}t|�}|j|�}t|�}|jd|k�|j|jd��dS)Nz$supervisor.process.EventListenerPoolznamed whatever>)rr
rr:r;r=)rr-rUr�r>rrrr?fs
z EventListenerPoolTests.test_reprc	Cs�t�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_t	�}d|_
ddlm}|j|_
|j|�|j�|j|jd	�|j|j|g�dS)
Nr)rrgz
/bin/process1)rm)rhr�)r�T)rr!rrr	r�r
rrirr�r��BUSYr�r�r0r&rwr�)	rr-rrjrgrUr�r�r�rrr�test_transition_nobody_readyns


z3EventListenerPoolTests.test_transition_nobody_readyc	Cs�t�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_t	�}ddlm
}d|_|j|_
|j|�|j�|j|jd	�|j|j|g�|j|jd
�|j|j
|j�dS)Nr)rrgz
/bin/process1)rm)rh)r�rCT�)rr!rrr	r�r
rrirr�r�r�r�r�r0r&rwr��stdin_buffer)	rr-rrjrgrUr�r�r�rrr�&test_transition_event_proc_not_runnings"


z=EventListenerPoolTests.test_transition_event_proc_not_runningcs�t�}ddlm}t|ddd�}t||jd�}t||gd��|j��}d|i|_t	�}ddlm
}|j|_G�fdd	�d	�}||_
|j|�|j�|j|jd
�|j|jg�|jjdd�\}	}
|j|
d
|
�|j|j|j�|j|j|�dS)Nr)rrgz
/bin/process1)rm)rh)r�cseZdZ�ZdS)zMEventListenerPoolTests.test_transition_event_proc_running.<locals>.DummyGroupN)r�r�r�r,r)rUrr�
DummyGroup�sr�T�
rCsdummy event)rr!rrr	rlr
rrirr�r�r�r�r�r0r&rwr�r�rcr�r�)rr-rrjrgr�r�r�r�r�r�r)rUr�"test_transition_event_proc_running�s(


z9EventListenerPoolTests.test_transition_event_proc_runningc	s�t�}ddlm}t|ddd�}t||jd�}t||gd��|j��}d|_t	j	�|_
d|i|_t�}ddlm
}|j|_G�fd	d
�d
�}||_|j|�|j�|j|jd�|j|j|g�dS)Nr)rrgz
/bin/process1)rm)rhr�)r�cseZdZ�ZdS)zkEventListenerPoolTests.test_transition_event_proc_running_with_dispatch_throttle_notyet.<locals>.DummyGroupN)r�r�r�r,r)rUrrr��sr�T)rr!rrr	rlr
r�dispatch_throttler��
last_dispatchrirr�r�r�r�r�r0r&rwr�)	rr-rrjrgr�r�r�r�r)rUr�@test_transition_event_proc_running_with_dispatch_throttle_notyet�s$



zWEventListenerPoolTests.test_transition_event_proc_running_with_dispatch_throttle_notyetcst�}ddlm}t|ddd�}t||jd�}t||gd��|j��}d|_t	j	�d|_
d|i|_t�}dd	lm
}|j|_G�fd
d�d�}||_|j|�|j�|j|jd�|j|jg�|jjd
d�\}	}
|j|
d|
�|j|j|j�|j|j|�dS)Nr)rrgz
/bin/process1)rm)rhr�i�)r�cseZdZ�ZdS)zjEventListenerPoolTests.test_transition_event_proc_running_with_dispatch_throttle_ready.<locals>.DummyGroupN)r�r�r�r,r)rUrrr��sr�Tr�rCsdummy event)rr!rrr	rlr
rr�r�r�rirr�r�r�r�r�r0r&rwr�r�rcr�r�)rr-rrjrgr�r�r�r�r�r�r)rUr�?test_transition_event_proc_running_with_dispatch_throttle_ready�s,


zVEventListenerPoolTests.test_transition_event_proc_running_with_dispatch_throttle_readyc
s�tj�d}t�}ddlm}t|ddd�}t||jd�}t||gd��|j��}d|_	||_
d|i|_t�}dd	lm
}|j|_G�fd
d�d�}	|	|_|j|�|j�|j|jd�|j|j|g�|j|j
|k�dS)
Nir)rrgz
/bin/process1)rm)rhr�)r�cseZdZ�ZdS)z|EventListenerPoolTests.test_transition_event_proc_running_with_dispatch_throttle_last_dispatch_in_future.<locals>.DummyGroupN)r�r�r�r,r)rUrrr��sr�T)r�rr!rrr	rlr
rr�r�rirr�r�r�r�r�r0r&rwr�r;)
rr�r-rrjrgr�r�r�r�r)rUr�Qtest_transition_event_proc_running_with_dispatch_throttle_last_dispatch_in_future�s(


zhEventListenerPoolTests.test_transition_event_proc_running_with_dispatch_throttle_last_dispatch_in_futurecCsvt�}ddlm}t|ddd�}t||jd�}t||gd�}|j|�}d|i|_t	�}|j
|�|j|j|�d�dS)Nr)rrgz
/bin/process1)rm)rhF)
rr!rrr	r�r
rrirr�r&�_dispatchEvent)rr-rrjrgrUr�r�rrr�test__dispatchEvent_notready�s


z3EventListenerPoolTests.test__dispatchEvent_notreadyc
s�t�}ddlm}t|ddd�}t||jd�}dd�}||_t||gd��|j��}d|i|_	t
�}dd	lm}|j|_
G�fd
d�d�}	|	|_|j|�|jt|j|�dS)Nr)rrgz
/bin/process1)rmcSsttj��dS)N)r�r�r�)r�rrr�raise_epipe	szcEventListenerPoolTests.test__dispatchEvent_proc_write_raises_non_EPIPE_OSError.<locals>.raise_epipe)rh)r�cseZdZ�ZdS)zbEventListenerPoolTests.test__dispatchEvent_proc_write_raises_non_EPIPE_OSError.<locals>.DummyGroupN)r�r�r�r,r)rUrrr�	sr�)rr!rrr	rlr�r
rrirr�r�r�r�r�rJr�r�)
rr-rrjrgr�r�r�r�r�r)rUr�7test__dispatchEvent_proc_write_raises_non_EPIPE_OSError�s 


zNEventListenerPoolTests.test__dispatchEvent_proc_write_raises_non_EPIPE_OSErrorN)r�r�r�r�rrr9r�r�r�r�r�r�r?r�r�r�r�r�r�r�r�rrrrr��s&r�c@s$eZdZdd�Zdd�Zdd�ZdS)�test_new_serialcCsddlm}||�S)Nr)�
new_serial)rr�)r�instr�rrr�_callFUT	sztest_new_serial._callFUTcsNddlm�G�fdd�dt�}|�}|j|�}|j|jd�|j|d�dS)Nr)rcseZdZ�fdd�ZdS)z8test_new_serial.test_inst_serial_is_maxint.<locals>.Instcs
�|_dS)N)r�)r)rrrr}	szAtest_new_serial.test_inst_serial_is_maxint.<locals>.Inst.__init__N)r�r�r�r}r)rrr�Inst	sr�)�supervisor.compatrrdr�r&r�)rr�r�ror)rr�test_inst_serial_is_maxint	s
z*test_new_serial.test_inst_serial_is_maxintcCs>Gdd�dt�}|�}|j|�}|j|jd�|j|d�dS)Nc@seZdZdd�ZdS)z<test_new_serial.test_inst_serial_is_not_maxint.<locals>.InstcSs
d|_dS)NrC)r�)rrrrr}"	szEtest_new_serial.test_inst_serial_is_not_maxint.<locals>.Inst.__init__N)r�r�r�r}rrrrr�!	sr�rX)rdr�r&r�)rr�r�rorrr�test_inst_serial_is_not_maxint 	s

z.test_new_serial.test_inst_serial_is_not_maxintN)r�r�r�r�r�r�rrrrr�	s
r�)#r�rar�r`r�Zunittestr�rrr�rrrrrr	r
rrr
rrrrrZsupervisor.optionsrZTestCaserrNreruryr�r�rrrr�<module>sVv"=