o
    þâf%U  ã                   @   sž   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mZ d dl	m
Z
 dejv r3d dlZejZneZG dd„ deƒZdd	„ Zed
krMejd	d dS dS )é    )Úunicode_literalsN©Ú	xmlrpclib©ÚSupervisorTransportÚ
END_TO_ENDc                   @   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%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3S )4ÚEndToEndTestsc                 C   sx   d}d}t  td¡}ddd|g}z&|tj|< tjtj|dd}|  	|j
tj¡ | |d	 | ¡ W tj|= d
S tj|= w )zÒWhen an environment variable whose value contains a percent sign is
        present in the environment before supervisord starts, the value is
        passed to the child without the percent sign being mangled.ÚSUPERVISOR_TEST_1441Bzfoo_%s_%_%%_%%%_%2_barzfixtures/issue-291a.confú-músupervisor.supervisordú-cúutf-8©Úencodingú=N)Úpkg_resourcesÚresource_filenameÚ__name__ÚosÚenvironÚpexpectÚspawnÚsysÚ
executableÚ
addCleanupÚkillÚsignalÚSIGINTÚexpect_exact)ÚselfÚkeyÚvalÚfilenameÚargsÚsupervisord© r%   úS/var/www/html/venv/lib/python3.10/site-packages/supervisor/tests/test_end_to_end.pyÚ;test_issue_291a_percent_signs_in_original_env_are_preserved   s   
zIEndToEndTests.test_issue_291a_percent_signs_in_original_env_are_preservedc                 C   sš   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ | d¡ dd	d|d
dg}tjtj|dd}|  |jt	j
¡ | d¡ | tj¡ dS )z‚When an environment variable is set in the [supervisord] section,
        it should be put into the environment of the subprocess.zfixtures/issue-550.confr
   r   r   r   r   z(success: print_env entered RUNNING statez+exited: print_env (exit status 0; expected)úsupervisor.supervisorctlztail -100000Ú	print_envzTHIS_SHOULD=BE_IN_CHILD_ENVN©r   r   r   r   r   r   r   r   r   r   r   r   ÚexpectÚEOF)r   r"   r#   r$   Úsupervisorctlr%   r%   r&   Útest_issue_550'   s   


zEndToEndTests.test_issue_550c                 C   ó¢   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ ddd|d	d
dg}tjtj|dd}|  |jt	j
¡ tddƒD ]}d| }|j|dd qAdS )zeWhen a log file has Unicode characters in it, 'supervisorctl
        tail -f name' should still work.zfixtures/issue-565.confr
   r   r   r   r   ú$success: hello entered RUNNING stater(   Útailú-fÚhelloé   é   u'   The Ã˜resund bridge ends in MalmÃ¶ - %dé   ©ÚtimeoutN©r   r   r   r   r   r   r   r   r   r   r   r   Úrange©r   r"   r#   r$   r-   ÚiÚliner%   r%   r&   Útest_issue_5657   ó   
þzEndToEndTests.test_issue_565c                 C   s   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ tjd dk }|r)d	}nd
}|jd| dd |jddd |rF|jddd dS dS )z‡When a process outputs something on its stdout or stderr file
        descriptor that is not valid UTF-8, supervisord should not crash.zfixtures/issue-638.confr
   r   r   r   r   r   é   Ú ÚbzUndecodable: %s'\x88\n'r6   r7   z)received SIGCH?LD indicating a child quitzVgave up: produce-unicode-error entered FATAL state, too many start retries too quicklyé<   N)r   r   r   r   r   r   r   r   r   r   r   Úversion_infor   r+   )r   r"   r#   r$   Úis_py2Úb_prefixr%   r%   r&   Útest_issue_638H   s   
ÿþzEndToEndTests.test_issue_638c                 C   sh   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ tdƒD ]}|jdd	d
 |jddd
 q!dS )zSWhen Supervisor is run on Python 3, the eventlistener protocol
        should work.zfixtures/issue-663.confr
   r   r   r   r   é   ÚOKREADYrC   r7   zBUSY -> ACKNOWLEDGEDr6   N)r   r   r   r   r   r   r   r   r   r   r   r:   r   )r   r"   r#   r$   r<   r%   r%   r&   Útest_issue_663[   s   þzEndToEndTests.test_issue_663c                 C   s¶   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ |jddd	 dd
d|dg}tjtj|dd}|  |jt	j
¡ z|jddd	 d}W n tjyS   d}Y nw |  |¡ dS )z¡When a subprocess name has Unicode characters, 'supervisord'
        should not send incomplete XML-RPC responses and 'supervisorctl
        status' should work.zfixtures/issue-664.confr
   r   r   r   r   u!   test_Ã¶Ã¤Ã¼ entered RUNNING staterC   r7   r(   Ústatusu   test_Ã¶Ã¤Ã¼\s+RUNNINGr6   TFN©r   r   r   r   r   r   r   r   r   r   r   r   r+   ÚExceptionPexpectÚ
assertTrue©r   r"   r#   r$   r-   Úseenr%   r%   r&   Útest_issue_664f   s   ÿzEndToEndTests.test_issue_664c                 C   s^   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ | d¡ | tj¡ d	S )
zzWhen a subprocess enters the FATAL state, a one-line eventlistener
        can be used to signal supervisord to shut down.zfixtures/issue-733.confr
   r   r   r   r   z(gave up: nonexistent entered FATAL statez(received SIGTERM indicating exit requestNr*   ©r   r"   r#   r$   r%   r%   r&   Útest_issue_733z   s   

zEndToEndTests.test_issue_733c                 C   s®   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ |jddd	 td
d
dƒ}t d|¡}z dD ]}|j d|¡}|  |¡ |j|dd	 q3W |j ¡  d S |j ¡  w )Nzfixtures/issue-835.confr
   r   r   r   r   úcat entered RUNNING staterC   r7   rA   zunix:///tmp/issue-835.sockzhttp://anything/RPC2)õ"   The Ã˜resund bridge ends in MalmÃ¶r3   Úcatr6   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   ÚServerProxyÚ
supervisorÚsendProcessStdinrN   Ú
connectionÚclose)r   r"   r#   r$   Ú	transportÚserverÚsÚresultr%   r%   r&   Útest_issue_835…   s   
ýzEndToEndTests.test_issue_835c                 C   sà   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ |jddd	 dd
d|ddg}tjtj|dd}|  |jt	j
¡ zdD ]}| |¡ |j|dd	 | |¡ | |¡ q@d}W n tjyh   d}Y nw |  |¡ d S )Nzfixtures/issue-836.confr
   r   r   r   r   rT   rC   r7   r(   ÚfgrV   )ÚHiÚHellorU   TF)r   r   r   r   r   r   r   r   r   r   r   r   ÚsendlinerM   rN   )r   r"   r#   r$   r-   r^   rP   r%   r%   r&   Útest_issue_836•   s&   

ÿzEndToEndTests.test_issue_836c                 C   óH   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ dS )	zyA percent sign can be used in a command= string without being
        expanded if it is escaped by a second percent sign.zfixtures/issue-986.confr
   r   r   r   r   z2dhcrelay -d -q -a %h:%p %P -i Vlan1000 192.168.0.1N©r   r   r   r   r   r   r   r   r   r   r   r   rR   r%   r%   r&   Ú1test_issue_986_command_string_with_double_percentª   s
   z?EndToEndTests.test_issue_986_command_string_with_double_percentc                 C   s¦   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ |jddd	 dd
d|dg}tjtj|dd}z|jddd	 d}W n tjyK   d}Y nw |  |¡ dS )zLWhen run on Python 3, the 'supervisorctl avail' command
        should work.zfixtures/issue-1054.confr
   r   r   r   r   rT   rC   r7   r(   Úavailzcat\s+in use\s+autor6   TFNrL   rO   r%   r%   r&   Útest_issue_1054³   s   ÿzEndToEndTests.test_issue_1054c                 C   rf   )	z¯When the [supervisord] section has a variable defined in
        environment=, that variable should be able to be used in an
        %(ENV_x) expansion in a [program] section.zfixtures/issue-1170a.confr
   r   r   r   r   zset from [supervisord] sectionNrg   rR   r%   r%   r&   Útest_issue_1170aÄ   s
   zEndToEndTests.test_issue_1170ac                 C   rf   )	záWhen the [supervisord] section has a variable defined in
        environment=, and a variable by the same name is defined in
        enviroment= of a [program] section, the one in the [program]
        section should be used.zfixtures/issue-1170b.confr
   r   r   r   r   zset from [program] sectionNrg   rR   r%   r%   r&   Útest_issue_1170bÎ   ó
   zEndToEndTests.test_issue_1170bc                 C   rf   )	zîWhen the [supervisord] section has a variable defined in
        environment=, and a variable by the same name is defined in
        enviroment= of an [eventlistener] section, the one in the
        [eventlistener] section should be used.zfixtures/issue-1170c.confr
   r   r   r   r   z set from [eventlistener] sectionNrg   rR   r%   r%   r&   Útest_issue_1170cÙ   rm   zEndToEndTests.test_issue_1170cc                 C   sL   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ |jddd	 d
S )zïWhen the main log file does not need rotation (logfile_maxbyte=0)
        then the non-rotating logger will be used to avoid an
        IllegalSeekError in the case that the user has configured a
        non-seekable file like /dev/stdout.zfixtures/issue-1224.confr
   r   r   r   r   rT   rC   r7   Nrg   rR   r%   r%   r&   Útest_issue_1224ä   s
   zEndToEndTests.test_issue_1224c                 C   r/   )úbWhen 'supervisorctl tail -f name' is run and the log contains
        unicode, it should not fail.zfixtures/issue-1231a.confr
   r   r   r   r   r0   r(   r1   r2   r3   r4   r5   õ   %d - hash=57d94bâ€¦381088r6   r7   Nr9   r;   r%   r%   r&   Útest_issue_1231aï   r?   zEndToEndTests.test_issue_1231ac              	   C   s  t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ ddd|d	d
dg}tj ¡ }d|d< tjtj|d|d}|  |jt	j
¡ tjdd… dk r]|jddd |jddd tddƒD ]#}d| }z	|j|dd W qb tjjy…   |  d|j¡ Y  dS w dS )rp   zfixtures/issue-1231b.confr
   r   r   r   r   r0   r(   r1   r2   r3   ÚoopsÚLANG©r   ÚenvNrH   ©r@   é   ú'Warning: sys.stdout.encoding is set to r6   r7   úUnicode output may fail.r4   r5   rq   z:Unable to write Unicode to stdout because it has encoding )r   r   r   r   r   r   r   r   r   r   r   r   r   r   ÚcopyrD   r+   r:   Ú
exceptionsr,   ÚassertInÚbefore)r   r"   r#   r$   rv   r-   r<   r=   r%   r%   r&   Útest_issue_1231b   s8   

ÿÿþüüzEndToEndTests.test_issue_1231bc                 C   sÀ   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ ddd|d	d
g}tj ¡ }d|d< tjtj|d|d}|  |jt	j
¡ tjdd… dk r^|jddd |jddd dS dS )rp   zfixtures/issue-1231c.confr
   r   r   r   r   r0   r(   r1   r3   rs   rt   ru   NrH   rw   ry   r6   r7   rz   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r{   rD   r+   )r   r"   r#   r$   rv   r-   r%   r%   r&   Útest_issue_1231c"  s$   

ÿÿýzEndToEndTests.test_issue_1231cc                 C   s˜   g d¢}t jtj|dd}|  |jtj¡ | d¡ | d¡ | 	t j
¡ g d¢}t jtj|dd}|  |jtj¡ | d¡ | d¡ | 	t j
¡ d	S )
z`When -? is given to supervisord or supervisorctl, help should be
        displayed like -h does.)r
   r   ú-?r   r   z(supervisord -- run a set of applicationsz(-l/--logfile FILENAME -- use FILENAME as)r
   r(   r   z%supervisorctl -- control applicationsz(-i/--interactive -- start an interactiveN)r   r   r   r   r   r   r   r   r   r+   r,   )r   r#   r$   r-   r%   r%   r&   Útest_issue_1251:  s   



zEndToEndTests.test_issue_1251c                 C   sˆ   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ dtj|f }tjd	d|gdd}|  |jt	j
¡ |jd
dd dS )z¢When the output of 'supervisorctl tail -f worker' is piped such as
        'supervisor tail -f worker | grep something', 'supervisorctl' should
        not crash.zfixtures/issue-1298.confr
   r   r   r   r   z#success: spew entered RUNNING statezC'%s' -m supervisor.supervisorctl -c '%s' tail -f spew | /bin/cat -uz/bin/shz	spewage 2r6   r7   N)r   r   r   r   r   r   r   r   r   r   r   r   r+   )r   r"   r#   r$   ÚcmdÚbashr%   r%   r&   Útest_issue_1298K  s   
ÿzEndToEndTests.test_issue_1298c                 C   óL   g d¢}t jtj|dd}|  |jtj¡ | t j	¡ |  
|j ¡ d¡ dS )z\When pidproxy is given a command to run that has no arguments, it
        runs that command.)r
   úsupervisor.pidproxyúnonexistent-pidfileú	/bin/echor   r   rA   N©r   r   r   r   r   r   r   r   r+   r,   ÚassertEqualr~   Ústrip©r   r#   Úpidproxyr%   r%   r&   Ú)test_issue_1418_pidproxy_cmd_with_no_args\  ó
   z7EndToEndTests.test_issue_1418_pidproxy_cmd_with_no_argsc                 C   r†   )zYWhen pidproxy is given a command to run that has arguments, it
        runs that command.)r
   r‡   rˆ   r‰   Ú1Ú2r   r   z1 2NrŠ   r   r%   r%   r&   Ú&test_issue_1418_pidproxy_cmd_with_argse  r   z4EndToEndTests.test_issue_1418_pidproxy_cmd_with_argsc           	      C   ó¦   t  td¡}ddd|g}tjtj|dd}|  |jt	j
¡ | d¡ dd	lm} dd
lm} |dddƒ}z| d|¡}|j ¡ }W | ¡  n| ¡  w |  |d¡ dS )zfWhen no identifier is supplied on the command line or in the config
        file, the default is used.zfixtures/issue-1483a.confr
   r   r   r   r   úsupervisord started with pidr   r   r   rA   zunix:///tmp/issue-1483a.sockú"http://transport.ignores.host/RPC2rX   N©r   r   r   r   r   r   r   r   r   r   r   r   Úsupervisor.compatr   Úsupervisor.xmlrpcr   rW   rX   ÚgetIdentificationr[   r‹   ©	r   r"   r#   r$   r   r   r\   r]   Úidentr%   r%   r&   Ú#test_issue_1483a_identifier_defaultn  ó   
z1EndToEndTests.test_issue_1483a_identifier_defaultc           	      C   r”   )zpWhen the identifier is supplied in the config file only, that
        identifier is used instead of the default.zfixtures/issue-1483b.confr
   r   r   r   r   r•   r   r   r   rA   zunix:///tmp/issue-1483b.sockr–   Úfrom_config_fileNr—   r›   r%   r%   r&   Ú,test_issue_1483b_identifier_from_config_file  rž   z:EndToEndTests.test_issue_1483b_identifier_from_config_filec           	      C   sª   t  td¡}ddd|ddg}tjtj|dd}|  |jt	j
¡ | d	¡ d
dlm} d
dlm} |dddƒ}z| d|¡}|j ¡ }W | ¡  n| ¡  w |  |d¡ dS )z~When an identifier is supplied in both the config file and on the
        command line, the one from the command line is used.zfixtures/issue-1483c.confr
   r   r   z-iÚfrom_command_liner   r   r•   r   r   r   rA   zunix:///tmp/issue-1483c.sockr–   Nr—   r›   r%   r%   r&   Ú-test_issue_1483c_identifier_from_command_line”  s   
z;EndToEndTests.test_issue_1483c_identifier_from_command_lineN)r   Ú
__module__Ú__qualname__r'   r.   r>   rG   rJ   rQ   rS   r`   re   rh   rj   rk   rl   rn   ro   rr   r   r€   r‚   r…   r   r“   r   r    r¢   r%   r%   r%   r&   r      s4    	
"		r   c                   C   s   t  tjt ¡S )N)ÚunittestÚfindTestCasesr   Úmodulesr   r%   r%   r%   r&   Ú
test_suite§  s   r¨   Ú__main__)ÚdefaultTest)Ú
__future__r   r   r   r   r¥   r   r˜   r   r™   r   r   r   ÚTestCaseÚBaseTestCaseÚobjectr   r¨   r   Úmainr%   r%   r%   r&   Ú<module>   s(   
   ÿ