+
    DfjV                     Z   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RI	H
t
HtHtHt ^ RIHt  ! R R4      t]P"                  ! ]4        ! R R]P$                  4      t ! R	 R
]P$                  4      t ! R R]P*                  4      t ! R R4      t ! R R]P$                  4      tR# )z(
Tests for L{twisted.python.threadpool}
N)TeamcreateMemoryWorker)contextfailure
threadable
threadpool)unittestc                   6   a  ] tR t^t o ^ tR tR tR.tRtV t	R# )Synchronizationc                `    Wn         W n        \        P                  ! 4       V n        . V n        R # N)Nwaiting	threadingLocklockruns)selfr   r   s   &&&>/usr/lib/python3/dist-packages/twisted/test/test_threadpool.py__init__Synchronization.__init__   s!    NN$		    c                :   V P                   P                  R 4      '       dT   \        V P                  4      ^,          '       g   \        P
                  ! R4       V P                   P                  4        MV ;P                  ^,          un        V P                   P                  4        V P                  P                  R4       \        V P                  4      V P                  8X  d   V P                  P                  4        V P                   P                  4        R# )Fg-C6*?N)r   acquirelenr   timesleepreleasefailuresappendr   r   r   s   &r   runSynchronization.run   s     99U##tyy>A%% 

6"IIMMQM
 					tyy>TVV#LL  "		r   r!   )r   r   r   r   N)
__name__
__module____qualname____firstlineno__r   r   r!   synchronized__static_attributes____classdictcell____classdict__s   @r   r
   r
      s     H0 7Lr   r
   c                      a  ] tR t^;t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tV 3R lR ltRtV tR# )ThreadPoolTestsz
Test threadpools.
c                    ^# )z4
Return number of seconds to wait before giving up.
 r    s   &r   
getTimeoutThreadPoolTests.getTimeout@        r   c                    \        R 4      pV F3  pVP                  R4      '       d    R# \        P                  ! R4       K5  	  V P	                  R4       R# )i@B Fgh㈵>z%A long time passed without succeedingN)ranger   r   r   fail)r   r   itemsis   &&  r   _waitForLockThreadPoolTests._waitForLockF   sB    gA||E""JJt 
 II=>r   c                    \         P                  ! ^^4      pV P                  VP                  ^4       V P                  VP                  ^4       R# )za
L{ThreadPool.min} and L{ThreadPool.max} are set to the values passed to
L{ThreadPool.__init__}.
N)r   
ThreadPoolassertEqualminmaxr   pools   & r   test_attributesThreadPoolTests.test_attributesO   s>    
 $$R,2&2&r   c                   \         P                  ! ^ ^4      pVP                  4        V P                  VP                  4       V P                  \        VP                  4      ^ 4       \         P                  ! ^^
4      pV P                  \        VP                  4      ^ 4       VP                  4        V P                  VP                  4       V P                  \        VP                  4      ^4       R# )zF
L{ThreadPool.start} creates the minimum number of threads specified.
N)r   r;   start
addCleanupstopr<   r   threadsr?   s   & r   
test_startThreadPoolTests.test_startX   s     $$Q*

		"T\\*A.$$Q+T\\*A.

		"T\\*A.r   c                    \         P                  ! ^ ^4      pVP                  4        VP                  4        VP	                  ^4       V P                  \        VP                  4      ^ 4       R# )zx
L{ThreadPool.adjustPoolsize} only modifies the pool size and does not
start new workers while the pool is not running.
N)r   r;   rD   rF   adjustPoolsizer<   r   rG   r?   s   & r   test_adjustingWhenPoolStopped-ThreadPoolTests.test_adjustingWhenPoolStoppedg   sO    
 $$Q*

		AT\\*A.r   c                   \         P                  ! ^ ^4      pVP                  4        V P                  VP                  4       V P                  VP                  . 4       R p ! R R4      pV! 4       p\        P                  ! V4      p\        P                  ! V4      pVP                  W$4       \        P                  ! 4       pVP                  VP                  4       VP                  V P                  4       4       ??\        P                   ! 4        V P#                  V! 4       4       V P#                  V! 4       4       R# )z
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.
c                     R # r   r/   )args   &r   worker<ThreadPoolTests.test_threadCreationArguments.<locals>.worker   s    r   c                       ] tR t^tRtR# ):ThreadPoolTests.test_threadCreationArguments.<locals>.Dumbr/   Nr#   r$   r%   r&   r(   r/   r   r   DumbrT          r   rV   N)r   r;   rD   rE   rF   r<   rG   weakrefrefcallInThreadr   Eventsetwaitr0   gccollectassertIsNone)r   tprQ   rV   unique	workerRef	uniqueRefevents   &       r   test_threadCreationArguments,ThreadPoolTests.test_threadCreationArgumentsr   s     ""1a(

  	R(		 	 KK'	KK'	 	' !
		"

4??$%


)+&)+&r   c                  a aaaa	a
aa \         P                  ! ^ ^4      pVP                  4        S P                  VP                  4       S P                  VP                  . 4       / o	\        P                  ! 4       o\        P                  ! 4       o. o
VVV	V
V VV3R lpV3R lp ! R R4      oS! 4       p\        P                  ! V4      p\        P                  ! V4      o\        P                  ! V4      oVP                  W#WDR7       ??SP                  4        SP                  S P                  4       4       \        P                   ! 4        S P#                  S! 4       4       S P#                  S! 4       4       ?\        P                   ! 4        S P#                  V! 4       4       S P#                  S
^ ,          ! 4       4       S P                  \%        S	P'                  4       4      RR.4       R# )zM
As C{test_threadCreationArguments} above, but for
callInThreadWithCallback.
c                   < \         P                  ! 4        SP                  SP                  4       4       S! 4       SR &   S! 4       SR&   SP	                  4        SP                  \        P                  ! V4      4       R# )rc   rd   N)r^   r_   r]   r0   r\   r   rX   rY   )	successresultonResultDoneonResultWaitrefdict	resultRefr   rd   rc   s	   &&r   onResultVThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.onResult   s^     JJLdoo/0#,;GK #,;GK W[[01r   c                    < S! 4       # r   r/   )rP   testrV   s   &&r   rQ   TThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.worker   s
    6Mr   c                       ] tR t^tRtR# )RThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.Dumbr/   NrU   r/   r   r   rV   rv      rW   r   rV   rs   N)r   r;   rD   rE   rF   r<   rG   r   r[   rX   rY   callInThreadWithCallbackr\   r]   r0   r^   r_   r`   listvalues)r   ra   rp   rQ   rb   onResultRefrV   rl   rm   rn   ro   rd   rc   s   f     @@@@@@@r   4test_threadCreationArgumentsCallInThreadWithCallbackDThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback   sq    ""1a(

  	R(  ( (		2 	2		 	 kk(+KK'	KK'	 	##Hf#J 	$//+,


)+&)+& 


+-()A,.) 	gnn./$>r   c                h   \         P                  ! ^^4      pV P                  VP                  ^4       V P                  VP                  ^4       \
        P                  ! \
        P                  ! V4      4      pV P                  VP                  ^4       V P                  VP                  ^4       R# )zm
Threadpools can be pickled and unpickled, which should preserve the
number of threads and other parameters.
N)r   r;   r<   r=   r>   pickleloadsdumps)r   r@   copys   &  r   test_persistence ThreadPoolTests.test_persistence   s    
 $$Q+1%2& ||FLL./1%2&r   c                   ^
p\         P                  ! 4       pVP                  4        V P                  VP                  4       \
        P                  ! 4       pVP                  4        \        W$4      p\        V4       F  pV! W54       K  	  V P                  V4       V P                  VP                  RVP                   R24       R# )z
Test synchronization of calls made with C{method}, which should be
one of the mechanisms of the threadpool to execute work in threads.
zrun() re-entered z timesN)r   r;   rD   rE   rF   r   r   r   r
   r4   r8   assertFalser   )r   methodr   ra   r   actorr7   s   &&     r   _threadpoolTestThreadPoolTests._threadpoolTest   s     ""$

 .."+qA2  	'"+<U^^<LF)STr   c                &    V P                  R 4      # )z/
Call C{_threadpoolTest} with C{callInThread}.
c                 8    V P                  VP                  4      # r   )rZ   r!   )ra   r   s   &&r   <lambda>3ThreadPoolTests.test_callInThread.<locals>.<lambda>  s    booeii6Pr   )r   r    s   &r   test_callInThread!ThreadPoolTests.test_callInThread  s     ##$PQQr   c                  a  ! R R\         4      oV3R lp\        P                  ! ^ ^4      pVP                  V4       VP	                  4        VP                  4        V P                  S4      pV P                  \        V4      ^4       R# )zQ
L{ThreadPool.callInThread} logs exceptions raised by the callable it
is passed.
c                       ] tR tRtRtR# )<ThreadPoolTests.test_callInThreadException.<locals>.NewErrori  r/   NrU   r/   r   r   NewErrorr     rW   r   r   c                     < S ! 4       hr   r/   r   s   r   
raiseError>ThreadPoolTests.test_callInThreadException.<locals>.raiseError      *r   N)		Exceptionr   r;   rZ   rD   rF   flushLoggedErrorsr<   r   )r   r   ra   errorsr   s   &   @r   test_callInThreadException*ThreadPoolTests.test_callInThreadException  sj    	y 		 ""1a(

#


	''1Va(r   c                  aa \         P                  ! 4       oSP                  4        . oVV3R lp\        P                  ! ^ ^4      pVP                  VR 4       VP                  4         V P                  S4       VP                  4        V P                  S^ ,          4       V P                  S^,          R4       R#   TP                  4        i ; i)z
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.
c                 l   < SP                  4        SP                  V 4       SP                  V4       R # r   r   r   rj   rk   resultswaiters   &&r   rp   ?ThreadPoolTests.test_callInThreadWithCallback.<locals>.onResult5  %    NNNN7#NN6"r   c                      R # rw   r/   r/   r   r   r   ?ThreadPoolTests.test_callInThreadWithCallback.<locals>.<lambda>;  s    fr   rs   N)r   r   r   r   r;   rx   rD   r8   rF   
assertTruer<   )r   rp   ra   r   r   s   &  @@r   test_callInThreadWithCallback-ThreadPoolTests.test_callInThreadWithCallback*  s     !	#
 ""1a(
##Hn=

	f%GGI
#V, GGIs   ,C   Cc                F  aaa  ! R R\         4      oV3R lp\        P                  ! 4       oSP                  4        . oVV3R lp\        P
                  ! ^ ^4      pVP                  W!4       VP                  4         V P                  S4       VP                  4        V P                  S^ ,          4       V P                  S^,          \        P                  4       V P                  \        S^,          P                   S4      4       R#   TP                  4        i ; i)z
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.
c                       ] tR tRtRtR# )RThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.NewErroriM  r/   NrU   r/   r   r   r   r   M  rW   r   r   c                     < S ! 4       hr   r/   r   s   r   r   TThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.raiseErrorP  r   r   c                 l   < SP                  4        SP                  V 4       SP                  V4       R # r   r   r   s   &&r   rp   RThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.onResultX  r   r   N)r   r   r   r   r   r;   rx   rD   r8   rF   r   assertIsInstancer   Failurer   
issubclasstype)r   r   rp   ra   r   r   r   s   &   @@@r   0test_callInThreadWithCallbackExceptionInCallback@ThreadPoolTests.test_callInThreadWithCallbackExceptionInCallbackF  s    	y 		 !	#
 ""1a(
##H9

	f%GGI$gaj'//:
71:??H=>	 GGIs    D D c                T  aa  ! R R\         4      o\        P                  ! 4       pVP                  4        . oVV3R lp\        P
                  ! ^ ^4      pVP                  VR 4       VP                  VP                  4       VP                  4         V P                  V4       VP                  4        V P                  S4      pV P                  \        V4      ^4       V P                  S^ ,          4       V P!                  S^,          4       R#   TP                  4        i ; i)zR
L{ThreadPool.callInThreadWithCallback} logs the exception raised by
C{onResult}.
c                       ] tR tRtRtR# )RThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.NewErrorip  r/   NrU   r/   r   r   r   r   p  rW   r   r   c                 V   < SP                  V 4       SP                  V4       S! 4       hr   )r   )rj   rk   r   r   s   &&r   rp   RThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.onResultx  s#    NN7#NN6"*r   c                      R # r   r/   r/   r   r   r   RThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.<lambda>~  s    dr   N)r   r   r   r   r   r;   rx   rZ   r   rD   r8   rF   r   r<   r   r   r`   )r   r   rp   ra   r   r   r   s   &    @@r   0test_callInThreadWithCallbackExceptionInOnResult@ThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResultj  s    	y 	 !	
 ""1a(
##Hl;
'

	f%GGI''1Va(
#'!*% GGIs   D D'c                  aa . o\         P                  ! 4       oVV3R lpV3R lp\        P                  ! ^ ^4      pVP	                  W4       VP                  4        V P                  VP                  4       SP                  V P                  4       4       V P                  \        S4      ^4       V P                  S^ ,          S^,          4       R# )zx
L{ThreadPool.callInThreadWithCallback} calls the function it is
given and the C{onResult} callback in the same thread.
c                    < SP                  \        P                  ! 4       P                  4       SP	                  4        R # r   )r   r   current_threadidentr\   )rj   rk   re   	threadIdss   &&r   rp   5ThreadPoolTests.test_callbackThread.<locals>.onResult  s)    Y557==>IIKr   c                  d   < S P                  \        P                  ! 4       P                  4       R # r   )r   r   r   r   )r   s   r   func1ThreadPoolTests.test_callbackThread.<locals>.func  s     Y557==>r   N)r   r[   r   r;   rx   rD   rE   rF   r]   r0   r<   r   )r   rp   r   ra   re   r   s   &   @@r   test_callbackThread#ThreadPoolTests.test_callbackThread  s    
 	!		? ""1a(
##H3

 

4??$%Y+1y|4r   c                8  aa \         P                  P                  4       P                  R,          pRVR&   . o\        P
                  ! 4       oVV3R lpV3R lp\        P                  ! ^ ^4      pVP                  W#4       VP                  4        V P                  VP                  4       SP                  V P                  4       4       V P                  \        S4      ^4       V P                  VS^ ,          4       V P                  VS^,          4       R# )z
The context L{ThreadPool.callInThreadWithCallback} is invoked in is
shared by the context the callable and C{onResult} callback are
invoked in.
zthis must be presenttestingc                    < \         P                  P                  4       P                  R,          pSP	                  V4       SP                  4        R#    N)r   theContextTrackercurrentContextcontextsr   r\   )rj   rk   ctxr   re   s   && r   rp   6ThreadPoolTests.test_callbackContext.<locals>.onResult  s7    ++::<EEbICOOC IIKr   c                     < \         P                  P                  4       P                  R,          p SP	                  V 4       R# r   )r   r   r   r   r   )r   r   s    r   r   2ThreadPoolTests.test_callbackContext.<locals>.func  s.    ++::<EEbICOOC r   Nr   )r   r   r   r   r   r[   r   r;   rx   rD   rE   rF   r]   r0   r<   r   )r   myctxrp   r   ra   r   re   s   &    @@r   test_callbackContext$ThreadPoolTests.test_callbackContext  s     ))88:CCBG1i!	
	! ""1a(
##H3

 

4??$%X*,,r   c                B   \         P                  ! 4       pVP                  4        \        P                  ! ^ ^4      pVP                  VP                  4       VP                  4         V P                  V4       VP                  4        R#   TP                  4        i ; i)z
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.
N)
r   r   r   r   r;   rZ   r   rD   r8   rF   )r   r   ra   s   &  r   test_existingWork!ThreadPoolTests.test_existingWork  sk     !""1a(
'

	f%GGIBGGIs   )B Bc                  aa \         P                  ! ^ ^4      pVP                  4        V P                  VP                  4       V P                  VP                  ^ 4       V P                  \        VP                  4      ^ 4       V P                  \        VP                  4      ^ 4       \        P                  ! 4       o\        P                  ! 4       oVV3R lpVP                  V4       SP                  ^
4       V P                  VP                  ^4       V P                  \        VP                  4      ^ 4       V P                  \        VP                  4      ^4       SP                  4        \        VP                  4      '       g   \        P                   ! R4       K3  V P                  \        VP                  4      ^4       V P                  \        VP                  4      ^ 4       R# )zc
As the worker receives and completes work, it transitions between
the working and waiting states.
c                  J   < SP                  4        S P                  ^
4       R# )
   N)r\   r]   )threadFinishthreadWorkings   r   _thread;ThreadPoolTests.test_workerStateTransition.<locals>._thread  s    b!r   gMb@?N)r   r;   rD   rE   rF   r<   workersr   waitersworkingr   r[   rZ   r]   r\   r   r   )r   r@   r   r   r   s   &  @@r   test_workerStateTransition*ThreadPoolTests.test_workerStateTransition  sX   
 $$Q*

		" 	q)T\\*A.T\\*A. ") (	" 	'"2q)T\\*A.T\\*A. 	dll##JJv 	T\\*A.T\\*A.r   c                   < V ^8  d   QhRR/# )   returnNr/   )formatr+   s   "r   __annotate__ThreadPoolTests.__annotate__  s     1 1 1r   c                    \         P                  ! ^ ^4      pV P                  VP                  P	                  4       ^ 4       R# )z2
There is a property '_queue' for legacy purposes
N)r   r;   r<   _queueqsizer?   s   & r   test_qThreadPoolTests.test_q  s3     $$Q***,a0r   r/   N)r#   r$   r%   r&   __doc__r0   r8   rA   rH   rL   rf   r|   r   r   r   r   r   r   r   r   r   r   r   r   r(   r)   r*   s   @r   r-   r-   ;   sw     ?'/	/('TH?T' U4R)(-8"?H!&F52-B$#/J1 1r   r-   c                   2   a  ] tR tRt o R tR tR tRtV tR# )RaceConditionTestsi  c                   a  \         P                  ! ^ ^
4      S n         \        P                  ! 4       S n        S P                   P                  4        V 3R lpS P                  V4       R# )    c                  @   < S P                   P                  4        S = R # r   )r   rF   r    s   r   done&RaceConditionTests.setUp.<locals>.done  s    OO  "r   N)r   r;   r   r[   re   rD   rE   )r   r   s   f r   setUpRaceConditionTests.setUp  sH    $//26__&
	  	r   c                    ^# )z-
A reasonable number of seconds to time out.
r/   r    s   &r   r0   RaceConditionTests.getTimeout  r2   r   c                   V P                  4       pV P                  P                  V P                  P                  4       V P                  P                  V4       V P                  P                  4        \        ^4       F2  pV P                  P                  V P                  P
                  4       K4  	  V P                  P                  V P                  P                  4       V P                  P                  V4       V P                  P                  4       '       g.   V P                  P	                  4        V P                  R4       R# R# )a-  
If multiple threads are waiting on an event (via blocking on something
in a callable passed to L{threadpool.ThreadPool.callInThread}), and
there is spare capacity in the threadpool, sending another callable
which will cause those to un-block to
L{threadpool.ThreadPool.callInThread} will reliably run that callable
and un-block the blocked threads promptly.

@note: This is not really a unit test, it is a stress-test.  You may
    need to run it with C{trial -u} to fail reliably if there is a
    problem.  It is very hard to regression-test for this particular
    bug - one where the thread pool may consider itself as having
    "enough capacity" when it really needs to spin up a new thread if
    it possibly can - in a deterministic way, since the bug can only be
    provoked by subtle race conditions.
z9'set' did not run in thread; timed out waiting on 'wait'.N)
r0   r   rZ   re   r\   r]   clearr4   isSetr5   )r   timeoutr7   s   &  r   test_synchronization'RaceConditionTests.test_synchronization  s    " //#$$TZZ^^4

 

qAOO((9 $$TZZ^^4

 zz!!JJNNIIQR "r   )re   r   N)	r#   r$   r%   r&   r   r0   r  r(   r)   r*   s   @r   r   r     s     	S Sr   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )
MemoryPooli6  zs
A deterministic threadpool that uses in-memory data structures to queue
work rather than threads to execute work.
c                r    Wn         W n        W0n        \        P                  P
                  ! V .VO5/ VB  R# )a\  
Initialize this L{MemoryPool} with a test case.

@param coordinator: a worker used to coordinate work in the L{Team}
    underlying this threadpool.
@type coordinator: L{twisted._threads.IExclusiveWorker}

@param failTest: A 1-argument callable taking an exception and raising
    a test-failure exception.
@type failTest: 1-argument callable taking (L{Failure}) and raising
    L{unittest.FailTest}.

@param newWorker: a 0-argument callable that produces a new
    L{twisted._threads.IWorker} provider on each invocation.
@type newWorker: 0-argument callable returning
    L{twisted._threads.IWorker}.
N)_coordinator	_failTest
_newWorkerr   r;   r   )r   coordinatorfailTest	newWorkerargskwargss   &&&&*,r   r   MemoryPool.__init__<  s2    $ (!#&&t=d=f=r   c                `   a aa VV V3R lp\        S P                  VS P                  R7      oS# )ag  
Override testing hook to create a deterministic threadpool.

@param currentLimit: A 1-argument callable which returns the current
    threadpool size limit.

@param threadFactory: ignored in this invocation; a 0-argument callable
    that would produce a thread.

@return: a L{Team} backed by the coordinator and worker passed to
    L{MemoryPool.__init__}.
c                     < SP                  4       p V P                  V P                  ,           S! 4       8  d   R # SP                  4       # r   )
statisticsbusyWorkerCountidleWorkerCountr  )statscurrentLimitr   teams    r   respectLimit&MemoryPool._pool.<locals>.respectLimita  s<     OO%E%%(=(==,.P??$$r   )r  createWorkerlogException)r   r  r  )r   r  threadFactoryr  r  s   ff& @r   _poolMemoryPool._poolS  s.    	% ))%

 r   )r  r  r  N)	r#   r$   r%   r&   r   r   r"  r(   r)   r*   s   @r   r
  r
  6  s     
>. r   r
  c                   0   a  ] tR tRt o RtR tR tRtV tR# )
PoolHelperir  a  
A L{PoolHelper} constructs a L{threadpool.ThreadPool} that doesn't actually
use threads, by using the internal interfaces in L{twisted._threads}.

@ivar performCoordination: a 0-argument callable that will perform one unit
    of "coordination" - work involved in delegating work to other threads -
    and return L{True} if it did any work, L{False} otherwise.

@ivar workers: the workers which represent the threads within the pool -
    the workers other than the coordinator.
@type workers: L{list} of 2-tuple of (L{IWorker}, C{workPerformer}) where
    C{workPerformer} is a 0-argument callable like C{performCoordination}.

@ivar threadpool: a modified L{threadpool.ThreadPool} to test.
@type threadpool: L{MemoryPool}
c                   a  \        4       w  pS n        . S n        V 3R lp\        WAP                  V.VO5/ VB S n        R# )z
Create a L{PoolHelper}.

@param testCase: a test case attached to this helper.

@type args: The arguments passed to a L{threadpool.ThreadPool}.

@type kwargs: The arguments passed to a L{threadpool.ThreadPool}
c                  ~   < S P                   P                  \        4       4       S P                   R,          ^ ,          # )r   r   )r   r   r   r    s   r   r  &PoolHelper.__init__.<locals>.newWorker  s-    LL 2 45<<#A&&r   N)r   performCoordinationr   r
  r5   r   )r   testCaser  r  r  r  s   f&*,  r   r   PoolHelper.__init__  sI     1C0D-T-	' %	
48
<B
r   c                6    V P                  4       '       d   K  R# )zq
Perform all currently scheduled "coordination", which is the work
involved in delegating work to other threads.
N)r)  r    s   &r   performAllCoordination!PoolHelper.performAllCoordination  s    
 &&(( )r   )r)  r   r   N)	r#   r$   r%   r&   r   r   r-  r(   r)   r*   s   @r   r%  r%  r  s     "
* r   r%  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MemoryBackedTestsi  zb
Tests using L{PoolHelper} to deterministically test properties of the
threadpool implementation.
c                v   \        V ^ ^
4      p^p\        V4       F  pVP                  P                  R 4       K!  	  VP	                  4        V P                  VP                  . 4       VP                  P                  4        VP	                  4        V P                  \        VP                  4      V4       R# )z
If a threadpool is told to do work before starting, then upon starting
up, it will start enough workers to handle all of the enqueued work
that it's been given.
c                      R # r   r/   r/   r   r   r   ;MemoryBackedTests.test_workBeforeStarting.<locals>.<lambda>      4r   N)	r%  r4   r   rZ   r-  r<   r   rD   r   r   helpernxs   &   r   test_workBeforeStarting)MemoryBackedTests.test_workBeforeStarting  s     D!R(qA**<8 %%',!%%'V^^,a0r   c                   \        V ^ ^
4      p^2p\        V4       F  pVP                  P                  R 4       K!  	  VP	                  4        V P                  VP                  . 4       VP                  P                  4        VP	                  4        V P                  \        VP                  4      VP                  P                  4       R# )z
If the amount of work before starting exceeds the maximum number of
threads allowed to the threadpool, only the maximum count will be
started.
c                      R # r   r/   r/   r   r   r   BMemoryBackedTests.test_tooMuchWorkBeforeStarting.<locals>.<lambda>  r4  r   N)
r%  r4   r   rZ   r-  r<   r   rD   r   r>   r5  s   &   r   test_tooMuchWorkBeforeStarting0MemoryBackedTests.test_tooMuchWorkBeforeStarting  s     D!R(qA**<8 %%',!%%'V^^,f.?.?.C.CDr   r/   N)	r#   r$   r%   r&   r   r9  r>  r(   r)   r*   s   @r   r0  r0    s     
1 E Er   r0  )r   r^   r   r   r   rX   twisted._threadsr   r   twisted.pythonr   r   r   r   twisted.trialr   r
   synchronizeSynchronousTestCaser-   r   r;   r
  r%  r0  r/   r   r   <module>rE     s   
 
     5 C C "! !H    'H1h22 H1V-S55 -S`9&& 9x- -`$E44 $Er   