Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyc


|Nc@sQdZddlZddlZddlZyddlZWnek
rSdZnXddlmZddl	m
Z
ddlmZm
Z
mZmZmZmZmZddlmZddlmZddlmZmZdd	lmZmZd
efdYZdefd
YZejj esMdZ!e!e_"e!e_"ndS(s
Whitebox tests for TCP APIs.
iN(tTestCase(tlog(tECONNABORTEDtENOMEMtENFILEtEMFILEtENOBUFStEINPROGRESStPort(t
ServerFactory(tplatform(t
maybeDeferredt
gatherResults(treactort
interfacestPlatformAssumptionsTestCasecBsVeZdZdZdZdZdZdZej	dkrTde_
nRS(s4
    Test assumptions about platform behaviors.
    i cCsg|_tdk	r}ddlm}t|d}tjtj|_tj	tj||jdf|d|_
ndS(Ni(t_listOpenFDsiiid(topenSocketstresourcetNonettwisted.internet.processRtlent	getrlimitt
RLIMIT_NOFILEtoriginalFileLimitt	setrlimittsocketLimit(tselfRtnewLimit((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pytsetUps	 cCs{x |jr"|jjjqWtdk	rwtjtjd}t|jd|}tj	tj||fndS(Nii(
RtpoptcloseRRRRtminRR(RtcurrentHardLimittnewSoftLimit((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyttearDown/scCs tj}|jj||S(s|
        Create and return a new socket object, also tracking it so it can be
        closed in the test tear down.
        (tsocketRtappend(Rts((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyR$<scCs|j}|jd|jd}|jd|j}|jtxkt|jD]M}y|jWq_tjk
r}|j	dt
tfkrPqq_Xq_W|jd|j
|jd|fdtf|jtj|j}|j
|j	dt
tfdS(s
        Test that the platform accept(2) call fails with either L{EMFILE} or
        L{ENOBUFS} when there are too many file descriptors open.
        s	127.0.0.1iiis7Could provoke neither EMFILE nor ENOBUFS from platform.N(s	127.0.0.1i(R$tbindtgetsocknametlistentsetblockingtFalsetxrangeRterrortargsRRtfailtassertInt
connect_exRtassertRaisestaccept(RtporttserverPortNumbertclienttitetexc((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyttest_acceptOutOfFilesFs$




twin32shWindows requires an unacceptably large amount of resources to provoke this behavior in the naive manner.(t__name__t
__module__t__doc__RRR#R$R:R
tgetTypetskip(((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyRs		
	
	%tSelectReactorTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
ejd	krrd
e
_
ndZejd	krde_
nRS(
s7
    Tests for select-specific failure conditions.
    cCs)g|_g|_tj|jjdS(N(tportstmessagesRtaddObserverR%(R((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyRws		cCs<tj|jjtg|jD]}t|j^q S(N(RtremoveObserverRCR%RRBRt
stopListening(Rtp((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyR#}scCs3t||d|}|j|jj||S(s
        Create, start, and return a new L{Port}, also tracking it so it can
        be stopped in the test tear down.
        t	interface(RtstartListeningRBR%(Rt
portNumbertfactoryRHRG((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyR4s
c
sdtffdY}t}|jd|dd}|j}z||_|jd}tj}||f}xD|jD]"}	|	jd|fkrPqqW|j	d|jfWd	||_Xd	S(
s
        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.
        t
FakeSocketcseZdZfdZRS(sI
            Pretend to be a socket in an overloaded system.
            cstjtjdS(N(R$R-toststrerror(R(tsocketErrorNumber(sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyR3s(R<R=R>R3((RO(sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyRLsiRHs	127.0.0.1s$Could not accept new connection (%s)tmessages+Log event for failed accept not found in %rN(
tobjectR	R4R$tdoReadterrnot	errorcodeRCtgetR/(
RRORLRKR4toriginalSockettexpectedFormattexpectedErrorCodetexpectedMessagetmsg((ROsC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyt_acceptFailureTests 		


	cCs
|jtS(s*
        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[R(R((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyttest_tooManyFilesFromAccepts	cCs
|jtS(s
        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[R(R((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyttest_noBufferSpaceFromAcceptscCs
|jtS(s
        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((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyt test_connectionAbortedFromAcceptscCs
|jtS(s
        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[R(R((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyttest_noFilesFromAcceptsR;s(Windows accept(2) cannot generate ENFILEcCs
|jtS(s
        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[R(R((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyttest_noMemoryFromAcceptss(Windows accept(2) cannot generate ENOMEM(R<R=R>RR#R4R[R\R]R^R_R
R?R@R`(((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyRArs				(						s?This test only applies to reactors that implement IReactorFDset(#R>RSR$RMRtImportErrorRttwisted.trial.unittestRttwisted.pythonRttwisted.internet.tcpRRRRRRRttwisted.internet.protocolR	ttwisted.python.runtimeR
ttwisted.internet.deferRRttwisted.internetR
RRRAt
IReactorFDSett
providedBytskipMsgR@(((sC/usr/lib/python2.7/dist-packages/twisted/test/test_tcp_internals.pyt<module>s$$

4Y