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_threadpool.pyc


=Nc@sdZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
mZmZm
Z
ddlmZddlmZdefdYZejed	ejfd
YZdejfdYZd
ejfdYZdS(s(
Tests for L{twisted.python.threadpool}
iN(tunittesttutil(t
threadpoolt
threadabletfailuretcontext(treactor(tDeferredtSynchronizationcBs)eZdZdZdZdgZRS(icCs.||_||_tj|_g|_dS(N(tNtwaitingt	threadingtLocktlocktruns(tselfR	R
((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt__init__s		cCs|jjtrEt|jds5tjdn|jjn|jd7_|jj|jj	dt|j|jkr|jjn|jjdS(Nig-C6*?i(
R
tacquiretFalsetlenRttimetsleeptreleasetfailurestappendtNoneR	R
(R((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytruns
R(t__name__t
__module__RRRtsynchronized(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRs		tThreadPoolTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
ejd	d
de
ge
_dZd
ZdZdZdZdZdZdZdZdZRS(s
    Test threadpools.
    cCsHxAtdD]&}|jtr&Pntjdq
W|jddS(Ni@Bgh㈵>s%A long time passed without succeeding(txrangeRRRRtfail(RR
ti((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt_waitForLock>s
cCs<tjdd}|j|jd|j|jddS(sy
        L{ThreadPool.min} and L{ThreadPool.max} are set to the values passed to
        L{ThreadPool.__init__}.
        iiN(Rt
ThreadPooltassertEqualtmintmax(Rtpool((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_attributesGscCstjdd}|j|j|j|jt|jdtjdd}|jt|jd|j|j|j|jt|jddS(sV
        L{ThreadPool.start} creates the minimum number of threads specified.
        iiii
N(RR#tstartt
addCleanuptstopR$Rtthreads(RR'((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt
test_startQs

cCstjdd}|j|j|j|j|jgd}dtfdY}|}tj	|}tj	|}|j
||tj}|j
|j
|j|j~~tj|j|d|j|ddS(s
        Test that creating threads in the threadpool with application-level
        objects as arguments doesn't results in those objects never being
        freed, with the thread maintaining a reference to them as long as it
        exists.
        iicSsdS(N((targ((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytworkerpstDumbcBseZRS((RR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR0ssN(RR#R)R*R+R$R,tobjecttweakreftreftcallInThreadRtEventtsettwaitt
getTimeouttgctcollectR(RttpR/R0tuniquet	workerReft	uniqueReftevent((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_threadCreationArgumentsas$
		
cstjdd}|jj|jj|jgitjtjgfd}fd}dt	fdY}t
j|}t
j|t
j||j|||d|~~t
jjjjjdjd~t
jj|djdddS(	se
        As C{test_threadCreationArguments} above, but for
        callInThreadWithCallback.
        iicsQjjd<d<jjtj|dS(NR=R>(R7R8R6RR2R3(tsuccesstresult(t	resultReftonResultDoneRR=tonResultWaitR>trefdict(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytonResults



csS(N((R.ttest(R0(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR/sR0cBseZRS((RR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR0sRHN(RR#R)R*R+R$R,RR5R1R2R3tcallInThreadWithCallbackR9R:R6R7R8R(RR;RGR/R<tonResultRef((RCRDR>R=RRER0RFs@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt4test_threadCreationArgumentsCallInThreadWithCallbacks6
!	


cCsztjdd}|j|jd|j|jdtjtj|}|j|jd|j|jddS(s
        Threadpools can be pickled and unpickled, which should preserve the
        number of threads and other parameters.
        iiN(RR#R$R%R&tpickletloadstdumps(RR'tcopy((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_persistencescCsd}tj}|j|j|jtj}|jt||}x!t	|D]}|||q^W|j
||j|jd|jfdS(s
        Test synchronization of calls made with C{method}, which should be
        one of the mechanisms of the threadpool to execute work in threads.
        i
srun() re-entered %d timesN(
RR#R)R*R+RRRRRR"tfailIfR(RtmethodR	R;R
tactorR!((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt_threadpoolTests	


cCs|jdS(s;
        Call C{_threadpoolTest} with C{dispatch}.
        cSs|j||jS(N(tdispatchR(R;RS((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt<lambda>s(RT(R((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt
test_dispatchstmessagesJdispatch\(\) is deprecated since Twisted 8.0, use callInThread\(\) insteadtcategorycCs|jdS(s?
        Call C{_threadpoolTest} with C{callInThread}.
        cSs|j|jS(N(R4R(R;RS((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRVs(RT(R((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_callInThread	scsdtfdYfd}tjdd}|j||j|j|j}|jt|ddS(si
        L{ThreadPool.callInThread} logs exceptions raised by the callable it
        is passed.
        tNewErrorcBseZRS((RR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR[scs
dS(N(((R[(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt
raiseErrorsiiN(	t	ExceptionRR#R4R)R+tflushLoggedErrorsR$R(RR\R;terrors((R[s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_callInThreadExceptions


cstjjgfd}tjdd}|j|d|jz|jWd|jX|j	d|j
dddS(s
        L{ThreadPool.callInThreadWithCallback} calls C{onResult} with a
        two-tuple of C{(True, result)} where C{result} is the value returned
        by the callable supplied.
        cs(jj|j|dS(N(RR(RARB(twaitertresults(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRG0s

iicSsdS(NRH((((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRV6sNRH(RRRRR#RIR)R"R+t
assertTrueR$(RRGR;((RaRbs@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_callInThreadWithCallback%s

csdtfdYfd}tjjgfd}tjdd}|j|||jz|jWd|j	X|j
d|jtdt
j|jtdjdS(s
        L{ThreadPool.callInThreadWithCallback} calls C{onResult} with a
        two-tuple of C{(False, failure)} where C{failure} represents the
        exception raised by the callable supplied.
        R[cBseZRS((RR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR[Hscs
dS(N(((R[(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR\Kscs(jj|j|dS(N(RR(RARB(RaRb(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRGSs

iiN(R]RRRRR#RIR)R"R+tassertFalseRct
isinstanceRtFailuret
issubclassttype(RR\RGR;((RaRbR[s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt0test_callInThreadWithCallbackExceptionInCallbackBs

csdtfdYtj}|jgfd}tjdd}|j|d|j|j|j	z|j
|Wd|jX|j}|j
t|d|jd|j
dddS(sj
        L{ThreadPool.callInThreadWithCallback} logs the exception raised by
        C{onResult}.
        R[cBseZRS((RR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR[kscs'j|j|dS(N(R(RARB(R[Rb(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRGss

iicSsdS(N(R(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRVysN(R]RRRRR#RIR4RR)R"R+R^R$RRcR(RRaRGR;R_((RbR[s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt0test_callInThreadWithCallbackExceptionInOnResultfs 

csgddltjfd}fd}tjdd}|j|||j|j|jj	|j
|jtd|jdddS(s
        L{ThreadPool.callInThreadWithCallback} calls the function it is
        given and the C{onResult} callback in the same thread.
        iNcs!jjjdS(N(Rt	get_identR6(RARB(R?tthreadt	threadIds(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRGscsjjdS(N(RRl((RmRn(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytfuncsiii(
RmRR5RR#RIR)R*R+R7R8R$R(RRGRoR;((RmRnR?s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_callbackThreads
cstjjjd}d|d<gtjfd}fd}tjdd}|j|||j	|j
|jj|j
|jtd|j|d|j|dd	S(
s
        The context L{ThreadPool.callInThreadWithCallback} is invoked in is
        shared by the context the callable and C{onResult} callback are
        invoked in.
        isthis must be presentttestingcs1tjjjd}j|jdS(Ni(RttheContextTrackertcurrentContexttcontextsRR6(RARBtctx(RtR?(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRGs
cs'tjjjd}j|dS(Ni(RRrRsRtR(Ru(Rt(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRosiiiN(RRrRsRtRR5RR#RIR)R*R+R7R8R$R(RtmyctxRGRoR;((RtR?s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_callbackContexts

cCsetj}|jtjdd}|j|j|jz|j|Wd|j	XdS(s
        Work added to the threadpool before its start should be executed once
        the threadpool is started: this is ensured by trying to release a lock
        previously acquired.
        iiN(
RRRRR#R4RR)R"R+(RRaR;((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_existingWorks

csOtjj|jjfd}|jtdt|dS(sB
        Test for the deprecation of the dispatch method.
        csjddS(NcSsdS(N(R(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRVs(RUR((R;(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytcbssFdispatch() is deprecated since Twisted 8.0, use callInThread() insteadN(RR#R)R*R+tassertWarnstDeprecationWarningt__file__(RRy((R;s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_dispatchDeprecations
	csOtjj|jjfd}|jtdt|dS(sN
        Test for the deprecation of the dispatchWithCallback method.
        csjddddS(NcSsdS(N(R(tx((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRVscSsdS(N(R(R~((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRVscSsdS(N(R(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRVs(tdispatchWithCallbackR((R;(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRys
smdispatchWithCallback() is deprecated since Twisted 8.0, use twisted.internet.threads.deferToThread() instead.N(RR#R)R*R+RzR{R|(RRy((R;s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt$test_dispatchWithCallbackDeprecations
	(RRt__doc__R"R(R-R@RKRPRTRWRtsuppressR{RZR`RdRjRkRpRwRxR}R(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR:s,			
		)	E								$	#		"		tRaceConditionTestCasecBs,eZdZdZdZdZRS(cCs5tj|_tjdd|_|jjdS(Nii
(RR5R?RR#R)(R((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytsetUpscCs|`|jj|`dS(N(R?RR+(R((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttearDowns
cCs|j}|jj|jj|jj||jjx*tdD]}|jj|jjqLW|jj|jj|jj||jjs|jj|j	dndS(s
        Test a race condition: ensure that actions run in the pool synchronize
        with actions run in the main thread.
        isActions not synchronizedN(
R8RR4R?R6R7tcleartrangetisSetR (RttimeoutR!((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_synchronizations

csmjjjdtfdfdfd}j|dS(s
        The submission of a new job to a thread pool in response to the
        C{onResult} callback does not cause a new thread to be added to the
        thread pool.

        This requires that the thread which calls C{onResult} to have first
        marked itself as available so that when the new job is queued, that
        thread may be considered to run it.  This is desirable so that when
        only N jobs are ever being executed in the thread pool at once only
        N threads will ever be created.
        icstj|dS(N(RtcallFromThread(RAtcounter(tsubmit(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRG1scs6r%jjfdn
jddS(NcsdS(Ni(((R(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRV7s(RRItcallbackR(R(RGRtloopDeferred(Rs@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyR4s	csjjjddS(Ni(R$Rtworkers(tignored(R(s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pytcbLoop;si
(R$RRRtaddCallback(RR((RRRGRs@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyttest_singleThread s
	

(RRRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRs			t!ThreadSafeListDeprecationTestCasecBseZdZdZRS(sT
    Test deprecation of threadpool.ThreadSafeList in twisted.python.threadpool
    cCsitj|j|jg}|jt|d|j|ddt|j|ddddS(sC
        Test deprecation of L{threadpool.ThreadSafeList}.
        iiRYRXstwisted.python.threadpool.ThreadSafeList was deprecated in Twisted 10.1.0: This was an internal implementation detail of support for Jython 2.1, which is now obsolete.N(RtThreadSafeListt
flushWarningsttest_threadSafeListR$RtassertIdenticalR{(Rt
warningsShown((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyRJs
(RRRR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyREs(RRLRR2R9Rt
twisted.trialRRttwisted.pythonRRRRttwisted.internetRttwisted.internet.deferRR1RtsynchronizetTestCaseRRR(((s@/usr/lib/python2.7/dist-packages/twisted/test/test_threadpool.pyt<module>s<"#
D