Your IP : 216.73.217.129


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_timeout.cpython-39.pyc

a

XC?h,�@s�dZddlZddlZddlmZddlmZe�d�Zddl	Z	ddl
Z
ddlZe��dd��Z
Gdd	�d	ej�ZGd
d�dej�ZGdd
�d
e�ZGdd�de�Zdd�Zedkr�e��dS)z&Unit tests for socket timeout feature.�N)�support)�
socket_helper�networkcCsJt�|��,t�||tjtj�ddWd�S1s<0YdS)z�Resolve an (host, port) to an address.

    We must perform name resolution before timeout tests, otherwise it will be
    performed by connect().
    r�N)r�transient_internet�socketZgetaddrinfo�AF_INET�SOCK_STREAM)ZhostZport�r
�6/opt/alt/python39/lib64/python3.9/test/test_timeout.py�resolve_addresss���rc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�CreationTestCasez9Test case for socket.gettimeout() and socket.settimeout()cCst�tjtj�|_dS�N)rrr	�sock��selfr
r
r�setUpszCreationTestCase.setUpcCs|j��dSr�r�closerr
r
r�tearDown"szCreationTestCase.tearDowncCs|�|j��dd�dS)Nztimeout not disabled by default)�assertEqualr�
gettimeoutrr
r
r�testObjectCreation%s�z#CreationTestCase.testObjectCreationcCs^|j�d�|�|j��d�|j�d�|�|j��d�|j�d�|�|j��d�dS)Ng�z�Ga@�)r�
settimeoutrrrr
r
r�testFloatReturnValue*sz%CreationTestCase.testFloatReturnValuecCsP|j�d�|�t|j���td��|j�d�|�t|j���td��dS)N���?g333333@)rrr�typerrr
r
r�testReturnType5szCreationTestCase.testReturnTypecCs�|j�d�|j�d�|j�d�|j�d�|�t|jjd�|�t|jjd�|�t|jjd�|�t|jjg�|�t|jji�|�t|jjd�dS)Nr��r
y)rr�assertRaises�	TypeErrorrr
r
r�
testTypeCheck=szCreationTestCase.testTypeCheckcCs:|�t|jjd�|�t|jjd�|�t|jjd�dS)N���g�)r"�
ValueErrorrrrr
r
r�testRangeCheckJszCreationTestCase.testRangeCheckcCs�|j�d�|j�d�|�|j��d�|j�d�|�|j��d�|j�d�|j�d�|�|j��d�|j�d�|�|j��d�dS)N�
TFr )rr�setblockingrrrr
r
r�testTimeoutThenBlockingPsz(CreationTestCase.testTimeoutThenBlockingcCsX|j�d�|j�d�|�|j��d�|j�d�|j�d�|�|j��d�dS)NFrT)rr)rrrrr
r
r�testBlockingThenTimeout^sz(CreationTestCase.testBlockingThenTimeoutN)
�__name__�
__module__�__qualname__�__doc__rrrrrr$r'r*r+r
r
r
rr
s
r
c@s*eZdZdZejZdd�ZeZdd�Z	dS)�TimeoutTestCaseg@cCs
t��dSr)�NotImplementedErrorrr
r
rrtszTimeoutTestCase.setUpc	Gs�|j�|�t|j|�}t|�D]Z}t��}z||�Wq tjyx}z&t��|}WYd}~q�WYd}~q d}~00q |�d�|�	|||j
�|�||d�dS)z�
        Test the specified socket method.

        The method is run at most `count` times and must raise a socket.timeout
        within `timeout` + self.fuzz seconds.
        Nzsocket.timeout was not raisedr)rr�getattr�range�time�	monotonicr�timeoutZfailZ
assertLess�fuzzZ
assertGreater)	r�countr6�method�args�i�t1�eZdeltar
r
r�_sock_operationys&
zTimeoutTestCase._sock_operationN)
r,r-r.r7rZHOST�	localhostrrr>r
r
r
rr0is
r0c@s\eZdZdZdd�Zdd�Ze�dd�dd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dS)�TCPTimeoutTestCasez3TCP test case for socket.socket() timeout functionscCs"t�tjtj�|_tdd�|_dS)Nzwww.python.org.�P)rrr	rr�addr_remoterr
r
rr�szTCPTimeoutTestCase.setUpcCs|j��dSrrrr
r
rr�szTCPTimeoutTestCase.tearDownTz*need to replace these hosts; see bpo-35518c
Cs$tdd�}tdd�}d}t�tjtj�}tj}|�|�zdz|�|�WnFtjy\Yn4t	y�}z|j
t
jkrzd}WYd}~n
d}~00W|��~n|��~0|r�|�
d�|d|d	||d|d	��||_t�|jd��"|�d	d
d|j�Wd�n1�s0YdS)Nzblackhole.snakebite.netiZ�zwhitehole.snakebite.neti[�TFz�We didn't receive a connection reset (RST) packet from {}:{} within {} seconds, so we're unable to test connect timeout against the corresponding {}:{} (which is configured to silently drop packets).rrg����MbP?�connect)rrrr	rZLOOPBACK_TIMEOUTrrCr6�OSError�errnoZECONNREFUSEDrZskipTest�formatrBrrr>)rZ	blackholeZ	whitehole�skiprr6�errr
r
r�testConnectTimeout�s<


���z%TCPTimeoutTestCase.testConnectTimeoutcCsRt�|jd��.|j�|j�|�dddd�Wd�n1sD0YdS)Nrr��?Zrecv�)rrrBrrCr>rr
r
r�testRecvTimeout�sz"TCPTimeoutTestCase.testRecvTimeoutcCs,t�|j|j�|j��|�ddd�dS)NrrJZaccept)r�	bind_portrr?�listenr>rr
r
r�testAcceptTimeout�s
z$TCPTimeoutTestCase.testAcceptTimeoutcCsnt�tjtj��J}t�||j�|��|j�|�	��|�
ddddd�Wd�n1s`0YdS)N�drJ�send�X�@
�rrr	rrMr?rNrrCZgetsocknamer>�rZservr
r
r�testSend�s
zTCPTimeoutTestCase.testSendc	Cstt�tjtj��P}t�||j�|��|j�|�	��|�
ddddd|�	��Wd�n1sf0YdS)NrPrJZsendtorRrSrTrUr
r
r�
testSendtos�zTCPTimeoutTestCase.testSendtocCsnt�tjtj��J}t�||j�|��|j�|�	��|�
ddddd�Wd�n1s`0YdS)NrPrJZsendallrRrSrTrUr
r
r�testSendalls
zTCPTimeoutTestCase.testSendallN)r,r-r.r/rr�unittestZskipIfrIrLrOrVrWrXr
r
r
rr@�s

Q	
r@c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�UDPTimeoutTestCasez3UDP test case for socket.socket() timeout functionscCst�tjtj�|_dSr)rrZ
SOCK_DGRAMrrr
r
rrszUDPTimeoutTestCase.setUpcCs|j��dSrrrr
r
rrszUDPTimeoutTestCase.tearDowncCs$t�|j|j�|�dddd�dS)NrrJZrecvfromrK)rrMrr?r>rr
r
r�testRecvfromTimeoutsz&UDPTimeoutTestCase.testRecvfromTimeoutN)r,r-r.r/rrr[r
r
r
rrZsrZcCst�d�dS)Nr)rZrequiresr
r
r
r�setUpModule%sr\�__main__)r/�	functoolsrY�testrZtest.supportrZis_resource_enabledZ
skip_expectedr4rEr�	lru_cacherZTestCaser
r0r@rZr\r,�mainr
r
r
r�<module>s$
M'