%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_tcp_internals.cpython-312.pyc

�

Ϫ�f�2���dZddlZddlZddlZ	ddlZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZmZddlmZmZmZmZmZmZmZmZmZmZmZddlmZdd	lm Z dd
l!m"Z"ee	jFjIe
�d�Gd�d
e"��Z%ee	jFjIe
�d�Gd�de"��Z&y#e$rdZY��wxYw)z
Whitebox tests for TCP APIs.
�N)�skipIf)�
interfaces�reactor)�
gatherResults�
maybeDeferred)�Protocol�
ServerFactory)�_ACCEPT_ERRORS�EAGAIN�ECONNABORTED�EINPROGRESS�EMFILE�ENFILE�ENOBUFS�ENOMEM�EPERM�EWOULDBLOCK�Port)�log)�platform)�TestCasez?This test only applies to reactors that implement IReactorFDsetc�h�eZdZdZdZd�Zd�Zd�Zee	j�dk(d�d��Zy	)
�PlatformAssumptionsTestsz4
    Test assumptions about platform behaviors.
    i c��g|_t�ddlm}t	|��dz}tj
tj�|_tjtj||jdf�|dz|_	yy)Nr)�_listOpenFDs���d)
�openSockets�resource�twisted.internet.processr�len�	getrlimit�
RLIMIT_NOFILE�originalFileLimit�	setrlimit�socketLimit)�selfr�newLimits   �A/usr/lib/python3/dist-packages/twisted/test/test_tcp_internals.py�setUpzPlatformAssumptionsTests.setUp4s{�������
>��<�>�*�Q�.�H�%-�%7�%7��8N�8N�%O�D�"�����&�&��4�3I�3I�!�3L�(M�
� (�#�~�D�� �c�^�|jr5|jj�j�|jr�5t�ftjtj
�d}t
|jd|�}tjtj
||f�yy)Nrr)	r�pop�closer r#r$�minr%r&)r(�currentHardLimit�newSoftLimits   r*�tearDownz!PlatformAssumptionsTests.tearDownFs��������� � �"�(�(�*������
 (�1�1�(�2H�2H�I�!�L���t�5�5�a�8�:J�K�L����x�5�5��FV�7W�X� r,c�d�tj�}|jj|�|S)z|
        Create and return a new socket object, also tracking it so it can be
        closed in the test tear down.
        )�socketr�append)r(�ss  r*r5zPlatformAssumptionsTests.socketRs(��

�M�M�O��������"��r,�win32zhWindows requires an unacceptably large amount of resources to provoke this behavior in the naive manner.c��|j�}|jd�|j�d}|jd�|j�}|j	d�t|j�D]}	|j��|jd�|j|jd|f�dtf�|jtj |j"�}|j|jdttf�y#t$r'}|jdttfvrYd}~���d}~wwxYw)	z�
        Test that the platform accept(2) call fails with either L{EMFILE} or
        L{ENOBUFS} when there are too many file descriptors open.
        )�	127.0.0.1rr�FrNz7Could provoke neither EMFILE nor ENOBUFS from platform.r:)r5�bind�getsockname�listen�setblocking�ranger'�OSError�argsrr�fail�assertIn�
connect_exr
�assertRaises�error�accept)r(�port�serverPortNumber�client�i�e�excs       r*�test_acceptOutOfFilesz.PlatformAssumptionsTests.test_acceptOutOfFiles[s ���{�{�}���	�	�"�#��+�+�-�a�0�����A����������5�!��t�'�'�(�	Q�A�
����
�	Q�
�I�I�O�P�	
�
�
����{�,<�=�>��K�@P�	
�
������d�k�k�:���
�
�c�h�h�q�k�F�G�#4�5��%�
��6�6�!�9��� 1�1����

�s�D � 	E�)E�
E�EN)�__name__�
__module__�__qualname__�__doc__r'r+r3r5rr�getTyperO�r,r*rr)sO��
��K�.�$
Y��������g�%�	5��
%6��
%6r,rc�\�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
eej�d	k(d
�d��Zeej�d	k(d�d
��Zeej"j%d�dk(d�d��Zeej�d	k(d�d��Zd�Zy)�SelectReactorTestsz7
    Tests for select-specific failure conditions.
    c�r�g|_g|_tj|jj�y�N)�ports�messagesr�addObserverr6�r(s r*r+zSelectReactorTests.setUp�s&����
���
�����
�
�,�,�-r,c���tj|jj�t	|j
D�cgc]}t
|j���c}�Scc}wrY)r�removeObserverr[r6rrZr�
stopListening)r(�ps  r*r3zSelectReactorTests.tearDown�s@�����4�=�=�/�/�0��d�j�j�Q��m�A�O�O�<�Q�R�R��Qs�A c�x�t|||��}|j�|jj|�|S)z
        Create, start, and return a new L{Port}, also tracking it so it can
        be stopped in the test tear down.
        ��	interface)r�startListeningrZr6)r(�
portNumber�factoryrdras     r*rIzSelectReactorTests.port�s5��

��W�	�:��	�����
�
���!���r,c���G�fd�d�}t�}|jd|d��}|j|d|��|j�d}tj
�}|jD�cgc],}|jd�|k(xr|jd	�|k(��.}}|jt|�dd
|j���ycc}w)a�
        Test behavior in the face of an exception from C{accept(2)}.

        On any exception which indicates the platform is unable or unwilling
        to allocate further resources to us, the existing port should remain
        listening, a message should be logged, and the exception should not
        propagate outward from doRead.

        @param socketErrorNumber: The errno to simulate from accept.
        c���eZdZdZ�fd�Zy)�9SelectReactorTests._acceptFailureTest.<locals>.FakeSocketzI
            Pretend to be a socket in an overloaded system.
            c�B��t�tj����rY)rA�os�strerror)r(�socketErrorNumbers �r*rHz@SelectReactorTests._acceptFailureTest.<locals>.FakeSocket.accept�s����/����=N�1O�P�Pr,N�rPrQrRrSrH)rns�r*�
FakeSocketrj�s���
�
Qr,rprr:rcr5z/Could not accept new connection ({acceptError})�
log_format�acceptErrorz)Log event for failed accept not found in N)
r	rI�patch�doRead�errno�	errorcoder[�get�
assertGreaterr")	r(rnrprgrI�expectedFormat�expectedErrorCode�msg�matchingMessagess	 `       r*�_acceptFailureTestz%SelectReactorTests._acceptFailureTest�s����	Q�	Q� �/���y�y��G�{�y�;���
�
�4��:�<�0����
�J��!�O�O�,=�>���}�}�
�
�����%��7�@��G�G�M�*�.?�?�@�
��
�	
���� �!�
�@D�
�
�O�	
��
s�71Cc�,�|jt�S)a*
        C{accept(2)} can fail with C{EMFILE} when there are too many open file
        descriptors in the process.  Test that this doesn't negatively impact
        any other existing connections.

        C{EMFILE} mainly occurs on Linux when the open file rlimit is
        encountered.
        )r}rr]s r*�test_tooManyFilesFromAcceptz.SelectReactorTests.test_tooManyFilesFromAccept�����&�&�v�.�.r,c�,�|jt�S)z�
        Similar to L{test_tooManyFilesFromAccept}, but test the case where
        C{accept(2)} fails with C{ENOBUFS}.

        This mainly occurs on Windows and FreeBSD, but may be possible on
        Linux and other platforms as well.
        )r}rr]s r*�test_noBufferSpaceFromAcceptz/SelectReactorTests.test_noBufferSpaceFromAccept�s���&�&�w�/�/r,c�,�|jt�S)z�
        Similar to L{test_tooManyFilesFromAccept}, but test the case where
        C{accept(2)} fails with C{ECONNABORTED}.

        It is not clear whether this is actually possible for TCP
        connections on modern versions of Linux.
        )r}rr]s r*� test_connectionAbortedFromAcceptz3SelectReactorTests.test_connectionAbortedFromAccept�s���&�&�|�4�4r,r8z(Windows accept(2) cannot generate ENFILEc�,�|jt�S)z�
        Similar to L{test_tooManyFilesFromAccept}, but test the case where
        C{accept(2)} fails with C{ENFILE}.

        This can occur on Linux when the system has exhausted (!) its supply
        of inodes.
        )r}rr]s r*�test_noFilesFromAcceptz)SelectReactorTests.test_noFilesFromAccept�r�r,z(Windows accept(2) cannot generate ENOMEMc�,�|jt�S)a�
        Similar to L{test_tooManyFilesFromAccept}, but test the case where
        C{accept(2)} fails with C{ENOMEM}.

        On Linux at least, this can sensibly occur, even in a Python program
        (which eats memory like no ones business), when memory has become
        fragmented or low memory has been filled (d_alloc calls
        kmem_cache_alloc calls kmalloc - kmalloc only allocates out of low
        memory).
        )r}rr]s r*�test_noMemoryFromAcceptz*SelectReactorTests.test_noMemoryFromAccept�s���&�&�v�.�.r,�INFRASTRUCTURE�AZUREPIPELINESz(Hangs on Azure Pipelines due to firewallc�8���t�}t|_|jd|d���|j	�j
�g��fd�}|j	|��fd�}�j
|��d�_�j�|j�jd��j
|���j�|j�jd��j�|j�jd�y)z�
        L{tcp.Port.doRead} increases the number of consecutive
        C{accept} calls it performs if all of the previous C{accept}
        calls succeed; otherwise, it reduces the number to the amount
        of successful calls.
        rr:rcc�4���D]}|j��yrY)r/)rK�clientss �r*�closeAllz7SelectReactorTests.test_acceptScaling.<locals>.closeAlls���!�
������
r,c����tjtjtj�}|jd�j	�j
f�|S)Nr:)r5�AF_INET�SOCK_STREAM�connect�getHostrI)rKrIs �r*r�z6SelectReactorTests.test_acceptScaling.<locals>.connects?����]�]�6�>�>�6�3E�3E�F�F��N�N�K�����)<�)<�=�>��Mr,rN)r	r�protocolrI�
addCleanupr`r6�
numberAcceptsrtrx�assertEqual)r(rgr�r�r�rIs    @@r*�test_acceptScalingz%SelectReactorTests.test_acceptScalings���� �/��#����y�y��G�{�y�;������*�*�+���	�	
����!�	�
	���w�y�!�������
����4�-�-�q�1����w�y�!����
�	
����+�+�Q�/����
�	
����+�+�Q�/r,z'Windows accept(2) cannot generate EPERMc������d�dg�G���fd�d�}t��D]1}�jtj|�j��3�j�j
|�j�dg�t
�}�jd|d��}d|_�j|d|��|j��j|jd�y	)
z�
        C{accept(2)} returning C{EPERM} is treated as a transient
        failure and the call retried no more than the maximum number
        of consecutive C{accept(2)} calls.
        �{rc� ��eZdZdZ���fd�Zy)�LSelectReactorTests.test_permissionFailure.<locals>.FakeSocketWithAcceptLimit��
            Pretend to be a socket in an overloaded system whose
            C{accept} method can only be called
            C{maximumNumberOfAccepts} times.
            c����dxxdz
cc<�d�kDr�jd�tttjt���)Nrrz(Maximum number of accept calls exceeded.)rCrArrlrm)�oself�acceptCalls�maximumNumberOfAcceptsr(s ���r*rHzSSelectReactorTests.test_permissionFailure.<locals>.FakeSocketWithAcceptLimit.acceptCsA����A��!�#���q�>�$:�:��I�I�H�I��e�R�[�[��%7�8�8r,Nro)r�r�r(s���r*�FakeSocketWithAcceptLimitr�<s
���
�
9r,r�r:rcr5rN)r@rFr5rGrH�failureExceptionr	rIr�rsrt�assertEquals)r(r��_rgrIr�r�s`    @@r*�test_permissionFailurez)SelectReactorTests.test_permissionFailure2s����"%���c��	9�	9��-�.�	P�A����f�l�l�,E�,G�,N�,N�O�	P�	
���$�/�/�1J�1L�1S�1S�T��c���/���y�y��G�{�y�;�� ����
�
�4��#<�#>�?�	
���
�	
���$�,�,�a�0r,c���tt�}|jttt
g�t
d�|D��dz�G�fd�d�}t�}|jd|d��}|j|d|��|j�|jtj�}|jdt|��|j|dj j"d��y	)
z}
        A C{socket.error} raised by C{accept(2)} whose C{errno} is
        unknown to the recovery logic is logged.
        c3�BK�|]}t|t�s�|���y�wrY)�
isinstance�int)�.0rGs  r*�	<genexpr>zBSelectReactorTests.test_unknownSocketErrorRaise.<locals>.<genexpr>gs����I�%�*�U�C�2H��I�s��rc���eZdZdZ�fd�Zy)�YSelectReactorTests.test_unknownSocketErrorRaise.<locals>.FakeSocketWithUnknownAcceptErrorr�c���t�d��)Nzunknown socket error message)rA)r��unknownAcceptErrors �r*rHz`SelectReactorTests.test_unknownSocketErrorRaise.<locals>.FakeSocketWithUnknownAcceptError.acceptqs����0�2P�Q�Qr,Nro)r�s�r*� FakeSocketWithUnknownAcceptErrorr�js���
�
Rr,r�rr:rcr5N)�listr
�extendrrr�maxr	rIrsrt�flushLoggedErrorsr5rGr�r"�valuerB)r(�knownErrorsr�rgrI�failuresr�s      @r*�test_unknownSocketErrorRaisez/SelectReactorTests.test_unknownSocketErrorRaise^s����
�>�*�����F�E�;�7�8�
�I�;�I�I�A�M�	�	R�	R� �/���y�y��G�{�y�;���
�
�4��#C�#E�F����
��)�)�&�,�,�7������C��M�*�����!��*�*�/�/��2�4F�Gr,N)rPrQrRrSr+r3rIr}rr�r�rrrTr�r�rl�environrwr�r�r�rUr,r*rWrW�s���
�.�
S��'
�R	/�0�5���H����'�)�+U�V�/�W�/���H����'�)�+U�V�/�W�/��
�
�
���'�(�,<�<�2��'0�	�'0�R��H����'�)�+T�U�)1�V�)1�VHr,rW)'rSrurlr5r �ImportError�unittestr�twisted.internetrr�twisted.internet.deferrr�twisted.internet.protocolrr	�twisted.internet.tcpr
rrr
rrrrrrr�twisted.pythonr�twisted.python.runtimer�twisted.trial.unittestr�
IReactorFDSet�
providedByrrWrUr,r*�<module>r�s����

�	�
����0�?�=������+�+��� � �+�+�G�4�4�E��X6�x�X6�	�X6�v�� � �+�+�G�4�4�E��pH��pH�	�pH��{���H��s�C�C�
C

Zerion Mini Shell 1.0