
    hV                     X   S r SSKrSSKrSSKrSSKrSSKrSSKJrJr  SSK	J
r
JrJrJr  SSKJr   " S S5      r\R"                  " \5         " S S	\R$                  5      r " S
 S\R$                  5      r " S S\R*                  5      r " S S5      r " S S\R$                  5      rg)z(
Tests for L{twisted.python.threadpool}
    N)TeamcreateMemoryWorker)contextfailure
threadable
threadpool)unittestc                   *    \ rS rSrSrS rS rS/rSrg)Synchronization   r   c                 ^    Xl         X l        [        R                  " 5       U l        / U l        g N)Nwaiting	threadingLocklockruns)selfr   r   s      c/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_threadpool.py__init__Synchronization.__init__   s!    NN$		    c                 "   U R                   R                  S5      (       aN  [        U R                  5      S-  (       d  [        R
                  " S5        U R                   R                  5         OU =R                  S-  sl        U R                   R                  5         U R                  R                  S 5        [        U R                  5      U R                  :X  a  U R                  R                  5         U R                   R                  5         g )NF   g-C6*?   )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__ r   r   r   r      s    H0 7Lr   r   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rSS jrSrg)ThreadPoolTests;   z
Test threadpools.
c                     g)z4
Return number of seconds to wait before giving up.
r   r-   r$   s    r   
getTimeoutThreadPoolTests.getTimeout@        r   c                     [        S5      nU H1  nUR                  S5      (       a    g [        R                  " S5        M3     U R	                  S5        g )Ni@B Fgh㈵>z%A long time passed without succeeding)ranger   r   r    fail)r   r   itemsis       r   _waitForLockThreadPoolTests._waitForLockF   sB    gA||E""JJt 
 II=>r   c                     [         R                  " SS5      nU R                  UR                  S5        U R                  UR                  S5        g)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                    [         R                  " SS5      nUR                  5         U R                  UR                  5        U R                  [        UR                  5      S5        [         R                  " SS5      nU R                  [        UR                  5      S5        UR                  5         U R                  UR                  5        U R                  [        UR                  5      S5        g)zF
L{ThreadPool.start} creates the minimum number of threads specified.
r   r      
   N)r   r?   start
addCleanupstopr@   r   threadsrC   s     r   
test_startThreadPoolTests.test_startX   s     $$Q*

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

		"T\\*A.r   c                     [         R                  " SS5      nUR                  5         UR                  5         UR	                  S5        U R                  [        UR                  5      S5        g)zx
L{ThreadPool.adjustPoolsize} only modifies the pool size and does not
start new workers while the pool is not running.
r   r      N)r   r?   rJ   rL   adjustPoolsizer@   r   rM   rC   s     r   test_adjustingWhenPoolStopped-ThreadPoolTests.test_adjustingWhenPoolStoppedg   sO    
 $$Q*

		AT\\*A.r   c                    [         R                  " SS5      nUR                  5         U R                  UR                  5        U R                  UR                  / 5        S n " S S5      nU" 5       n[        R                  " U5      n[        R                  " U5      nUR                  X$5        [        R                  " 5       nUR                  UR                  5        UR                  U R                  5       5        AA[        R                   " 5         U R#                  U" 5       5        U R#                  U" 5       5        g)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.
r   r   c                     g r   r-   )args    r   worker<ThreadPoolTests.test_threadCreationArguments.<locals>.worker   s    r   c                       \ rS rSrSrg):ThreadPoolTests.test_threadCreationArguments.<locals>.Dumb   r-   Nr'   r(   r)   r*   r,   r-   r   r   Dumbr[          r   r^   N)r   r?   rJ   rK   rL   r@   rM   weakrefrefcallInThreadr   Eventsetwaitr2   gccollectassertIsNone)r   tprX   r^   unique	workerRef	uniqueRefevents           r   test_threadCreationArguments,ThreadPoolTests.test_threadCreationArgumentsr   s     ""1a(

  	R(		 	 KK'	KK'	 	' !
		"

4??$%


)+&)+&r   c                   ^ ^^^^	^
^^ [         R                  " SS5      nUR                  5         T R                  UR                  5        T R                  UR                  / 5        0 m	[        R                  " 5       m[        R                  " 5       m/ m
UUU	U
U UU4S jnU4S jn " S S5      mT" 5       n[        R                  " U5      n[        R                  " U5      m[        R                  " U5      mUR                  X#XDS9  AATR                  5         TR                  T R                  5       5        [        R                   " 5         T R#                  T" 5       5        T R#                  T" 5       5        A[        R                   " 5         T R#                  U" 5       5        T R#                  T
S   " 5       5        T R                  [%        T	R'                  5       5      SS/5        g)	zM
As C{test_threadCreationArguments} above, but for
callInThreadWithCallback.
r   r   c                    > [         R                  " 5         TR                  TR                  5       5        T" 5       TS'   T" 5       TS'   TR	                  5         TR                  [        R                  " U5      5        g )Nrk   rl   )rf   rg   re   r2   rd   r#   r`   ra   )	successresultonResultDoneonResultWaitrefdict	resultRefr   rl   rk   s	     r   onResultVThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.onResult   s^     JJLdoo/0#,;GK #,;GK W[[01r   c                    > T" 5       $ r   r-   )rW   testr^   s     r   rX   TThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.worker   s
    6Mr   c                       \ rS rSrSrg)RThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.Dumb   r-   Nr]   r-   r   r   r^   r~      r_   r   r^   )r{   N)r   r?   rJ   rK   rL   r@   rM   r   rc   r`   ra   callInThreadWithCallbackrd   re   r2   rf   rg   rh   listvalues)r   ri   rx   rX   rj   onResultRefr^   rt   ru   rv   rw   rl   rk   s   `     @@@@@@@r   4test_threadCreationArgumentsCallInThreadWithCallbackDThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback   sq    ""1a(

  	R(  ( (		2 	2		 	 kk(+KK'	KK'	 	##Hf#J 	$//+,


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


+-()A,.) 	gnn./$>r   c                 f   [         R                  " SS5      nU R                  UR                  S5        U R                  UR                  S5        [
        R                  " [
        R                  " U5      5      nU R                  UR                  S5        U R                  UR                  S5        g)zm
Threadpools can be pickled and unpickled, which should preserve the
number of threads and other parameters.
   r   N)r   r?   r@   rA   rB   pickleloadsdumps)r   rD   copys      r   test_persistence ThreadPoolTests.test_persistence   s    
 $$Q+1%2& ||FLL./1%2&r   c                    Sn[         R                  " 5       nUR                  5         U R                  UR                  5        [
        R                  " 5       nUR                  5         [        X$5      n[        U5       H  nU" X55        M     U R                  U5        U R                  UR                  SUR                   S35        g)z
Test synchronization of calls made with C{method}, which should be
one of the mechanisms of the threadpool to execute work in threads.
rI   zrun() re-entered z timesN)r   r?   rJ   rK   rL   r   r   r   r   r6   r:   assertFalser"   )r   methodr   ri   r   actorr9   s          r   _threadpoolTestThreadPoolTests._threadpoolTest   s     ""$

 .."+qA2  	'"+<U^^<LF)STr   c                 &    U R                  S 5      $ )z/
Call C{_threadpoolTest} with C{callInThread}.
c                 8    U R                  UR                  5      $ r   )rb   r%   )ri   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                   ^  " S S[         5      mU4S jn[        R                  " SS5      nUR                  U5        UR	                  5         UR                  5         U R                  T5      nU R                  [        U5      S5        g)zQ
L{ThreadPool.callInThread} logs exceptions raised by the callable it
is passed.
c                       \ rS rSrSrg)<ThreadPoolTests.test_callInThreadException.<locals>.NewErrori  r-   Nr]   r-   r   r   NewErrorr     r_   r   r   c                     > T " 5       er   r-   r   s   r   
raiseError>ThreadPoolTests.test_callInThreadException.<locals>.raiseError      *r   r   r   N)		Exceptionr   r?   rb   rJ   rL   flushLoggedErrorsr@   r   )r   r   ri   errorsr   s       @r   test_callInThreadException*ThreadPoolTests.test_callInThreadException  sj    	y 		 ""1a(

#


	''1Va(r   c                   ^^ [         R                  " 5       mTR                  5         / mUU4S jn[        R                  " SS5      nUR                  US 5        UR                  5          U R                  T5        UR                  5         U R                  TS   5        U R                  TS   S5        g! UR                  5         f = f)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                 j   > TR                  5         TR                  U 5        TR                  U5        g r   r!   r#   rr   rs   resultswaiters     r   rx   ?ThreadPoolTests.test_callInThreadWithCallback.<locals>.onResult5  %    NNNN7#NN6"r   r   r   c                      g)Nr{   r-   r-   r   r   r   ?ThreadPoolTests.test_callInThreadWithCallback.<locals>.<lambda>;  s    fr   r{   N)r   r   r   r   r?   r   rJ   r:   rL   
assertTruer@   )r   rx   ri   r   r   s      @@r   test_callInThreadWithCallback-ThreadPoolTests.test_callInThreadWithCallback*  s     !	#
 ""1a(
##Hn=

	f%GGI
#V, GGIs   ,B7 7C	c                 ,  ^^^  " S S[         5      mU4S jn[        R                  " 5       mTR                  5         / mUU4S jn[        R
                  " SS5      nUR                  X!5        UR                  5          U R                  T5        UR                  5         U R                  TS   5        U R                  TS   [        R                  5        U R                  [        TS   R                   T5      5        g! UR                  5         f = f)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                       \ rS rSrSrg)RThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.NewErroriM  r-   Nr]   r-   r   r   r   r   M  r_   r   r   c                     > T " 5       er   r-   r   s   r   r   TThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.raiseErrorP  r   r   c                 j   > TR                  5         TR                  U 5        TR                  U5        g r   r   r   s     r   rx   RThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.onResultX  r   r   r   r   N)r   r   r   r   r   r?   r   rJ   r:   rL   r   assertIsInstancer   Failurer   
issubclasstype)r   r   rx   ri   r   r   r   s       @@@r   0test_callInThreadWithCallbackExceptionInCallback@ThreadPoolTests.test_callInThreadWithCallbackExceptionInCallbackF  s    	y 		 !	#
 ""1a(
##H9

	f%GGI$gaj'//:
71:??H=>	 GGIs    D Dc                 B  ^^  " S S[         5      m[        R                  " 5       nUR                  5         / mUU4S jn[        R
                  " SS5      nUR                  US 5        UR                  UR                  5        UR                  5          U R                  U5        UR                  5         U R                  T5      nU R                  [        U5      S5        U R                  TS   5        U R!                  TS   5        g! UR                  5         f = f)zR
L{ThreadPool.callInThreadWithCallback} logs the exception raised by
C{onResult}.
c                       \ rS rSrSrg)RThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.NewErrorip  r-   Nr]   r-   r   r   r   r   p  r_   r   r   c                 V   > TR                  U 5        TR                  U5        T" 5       er   )r#   )rr   rs   r   r   s     r   rx   RThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.onResultx  s#    NN7#NN6"*r   r   r   c                      g r   r-   r-   r   r   r   RThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.<lambda>~  s    dr   N)r   r   r   r   r   r?   r   rb   r!   rJ   r:   rL   r   r@   r   r   rh   )r   r   rx   ri   r   r   r   s        @@r   0test_callInThreadWithCallbackExceptionInOnResult@ThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResultj  s    	y 	 !	
 ""1a(
##Hl;
'

	f%GGI''1Va(
#'!*% GGIs   D Dc                   ^^ / m[         R                  " 5       mUU4S jnU4S jn[        R                  " SS5      nUR	                  X5        UR                  5         U R                  UR                  5        TR                  U R                  5       5        U R                  [        T5      S5        U R                  TS   TS   5        g)zx
L{ThreadPool.callInThreadWithCallback} calls the function it is
given and the C{onResult} callback in the same thread.
c                    > TR                  [        R                  " 5       R                  5        TR	                  5         g r   )r#   r   current_threadidentrd   )rr   rs   rm   	threadIdss     r   rx   5ThreadPoolTests.test_callbackThread.<locals>.onResult  s)    Y557==>IIKr   c                  b   > T R                  [        R                  " 5       R                  5        g r   )r#   r   r   r   )r   s   r   func1ThreadPoolTests.test_callbackThread.<locals>.func  s     Y557==>r   r   r   rQ   N)r   rc   r   r?   r   rJ   rK   rL   re   r2   r@   r   )r   rx   r   ri   rm   r   s       @@r   test_callbackThread#ThreadPoolTests.test_callbackThread  s    
 	!		? ""1a(
##H3

 

4??$%Y+1y|4r   c                   ^^ [         R                  R                  5       R                  S   nSUS'   / m[        R
                  " 5       mUU4S jnU4S jn[        R                  " SS5      nUR                  X#5        UR                  5         U R                  UR                  5        TR                  U R                  5       5        U R                  [        T5      S5        U R                  UTS   5        U R                  UTS   5        g	)
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                    > [         R                  R                  5       R                  S   nTR	                  U5        TR                  5         g Nr   )r   theContextTrackercurrentContextcontextsr#   rd   )rr   rs   ctxr   rm   s      r   rx   6ThreadPoolTests.test_callbackContext.<locals>.onResult  s7    ++::<EEbICOOC IIKr   c                  ~   > [         R                  R                  5       R                  S   n TR	                  U 5        g r   )r   r   r   r   r#   )r   r   s    r   r   2ThreadPoolTests.test_callbackContext.<locals>.func  s.    ++::<EEbICOOC r   r   r   rQ   N)r   r   r   r   r   rc   r   r?   r   rJ   rK   rL   re   r2   r@   r   )r   myctxrx   r   ri   r   rm   s        @@r   test_callbackContext$ThreadPoolTests.test_callbackContext  s     ))88:CCBG1i!	
	! ""1a(
##H3

 

4??$%X*,,r   c                 @   [         R                  " 5       nUR                  5         [        R                  " SS5      nUR                  UR                  5        UR                  5          U R                  U5        UR                  5         g! UR                  5         f = f)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.
r   r   N)
r   r   r   r   r?   rb   r!   rJ   r:   rL   )r   r   ri   s      r   test_existingWork!ThreadPoolTests.test_existingWork  sk     !""1a(
'

	f%GGIBGGIs   )B Bc                   ^^ [         R                  " SS5      nUR                  5         U R                  UR                  5        U R                  UR                  S5        U R                  [        UR                  5      S5        U R                  [        UR                  5      S5        [        R                  " 5       m[        R                  " 5       mUU4S jnUR                  U5        TR                  S5        U R                  UR                  S5        U R                  [        UR                  5      S5        U R                  [        UR                  5      S5        TR                  5         [        UR                  5      (       d2  [        R                   " S5        [        UR                  5      (       d  M2  U R                  [        UR                  5      S5        U R                  [        UR                  5      S5        g)zc
As the worker receives and completes work, it transitions between
the working and waiting states.
r   r   c                  H   > TR                  5         T R                  S5        g )NrI   )rd   re   )threadFinishthreadWorkings   r   _thread;ThreadPoolTests.test_workerStateTransition.<locals>._thread  s    b!r   rI   gMb@?N)r   r?   rJ   rK   rL   r@   workersr   waitersworkingr   rc   rb   re   rd   r   r    )r   rD   r   r   r   s      @@r   test_workerStateTransition*ThreadPoolTests.test_workerStateTransition  si   
 $$Q*

		" 	q)T\\*A.T\\*A. ") (	" 	'"2q)T\\*A.T\\*A. 	dll##JJv dll## 	T\\*A.T\\*A.r   Nc                     [         R                  " SS5      nU R                  UR                  R	                  5       S5        g)z2
There is a property '_queue' for legacy purposes
r   r   N)r   r?   r@   _queueqsizerC   s     r   test_qThreadPoolTests.test_q  s3     $$Q***,a0r   r-   )returnN)r'   r(   r)   r*   __doc__r2   r:   rE   rN   rS   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r,   r-   r   r   r/   r/   ;   so    ?'/	/('TH?T' U4R)(-8"?H!&F52-B$#/J1r   r/   c                   &    \ rS rSrS rS rS rSrg)RaceConditionTestsi  c                    ^  [         R                  " SS5      T l         [        R                  " 5       T l        T R                   R                  5         U 4S jnT R                  U5        g )Nr   rI   c                  >   > T R                   R                  5         T ? g r   )r   rL   r$   s   r   done&RaceConditionTests.setUp.<locals>.done  s    OO  "r   )r   r?   r   rc   rm   rJ   rK   )r   r   s   ` r   setUpRaceConditionTests.setUp  sH    $//26__&
	  	r   c                     g)z-
A reasonable number of seconds to time out.
r   r-   r$   s    r   r2   RaceConditionTests.getTimeout  r4   r   c                    U R                  5       nU R                  R                  U R                  R                  5        U R                  R                  U5        U R                  R                  5         [        S5       H2  nU R                  R                  U R                  R
                  5        M4     U R                  R                  U R                  R                  5        U R                  R                  U5        U R                  R                  5       (       d,  U R                  R	                  5         U R                  S5        gg)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.
rH   z9'set' did not run in thread; timed out waiting on 'wait'.N)
r2   r   rb   rm   rd   re   clearr6   isSetr7   )r   timeoutr9   s      r   test_synchronization'RaceConditionTests.test_synchronization  s    " //#$$TZZ^^4

 

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

 zz!!JJNNIIQR "r   )rm   r   N)r'   r(   r)   r*   r   r2   r  r,   r-   r   r   r   r     s    	Sr   r   c                   $    \ rS rSrSrS rS rSrg)
MemoryPooli6  zs
A deterministic threadpool that uses in-memory data structures to queue
work rather than threads to execute work.
c                 p    Xl         X l        X0l        [        R                  R
                  " U /UQ70 UD6  g)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                 Z   ^ ^^ UU U4S jn[        T R                  UT R                  S9mT$ )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                     > TR                  5       n U R                  U R                  -   T" 5       :  a  g TR                  5       $ 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   ``  @r   _poolMemoryPool._poolS  s.    	% ))%

 r   )r  r  r  N)r'   r(   r)   r*   r   r   r#  r,   r-   r   r   r  r  6  s    
>.r   r  c                   $    \ rS rSrSrS rS rSrg)
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                    ^  [        5       u  nT l        / T l        U 4S jn[        XAR                  U/UQ70 UD6T l        g)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                  n   > T R                   R                  [        5       5        T R                   S   S   $ )Nr   r   )r   r#   r   r$   s   r   r  &PoolHelper.__init__.<locals>.newWorker  s-    LL 2 45<<#A&&r   N)r   performCoordinationr   r  r7   r   )r   testCaser  r  r  r  s   `     r   r   PoolHelper.__init__  sI     1C0D-T-	' %	
48
<B
r   c                 `    U R                  5       (       a   U R                  5       (       a  M  gg)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   r   r&  r&  r  s    "
*r   r&  c                   $    \ rS rSrSrS rS rSrg)MemoryBackedTestsi  zb
Tests using L{PoolHelper} to deterministically test properties of the
threadpool implementation.
c                 t   [        U SS5      nSn[        U5       H  nUR                  R                  S 5        M!     UR	                  5         U R                  UR                  / 5        UR                  R                  5         UR	                  5         U R                  [        UR                  5      U5        g)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.
r   rI   r   c                      g r   r-   r-   r   r   r   ;MemoryBackedTests.test_workBeforeStarting.<locals>.<lambda>      4r   N)	r&  r6   r   rb   r.  r@   r   rJ   r   r   helpernxs       r   test_workBeforeStarting)MemoryBackedTests.test_workBeforeStarting  s     D!R(qA**<8 %%',!%%'V^^,a0r   c                    [        U SS5      nSn[        U5       H  nUR                  R                  S 5        M!     UR	                  5         U R                  UR                  / 5        UR                  R                  5         UR	                  5         U R                  [        UR                  5      UR                  R                  5        g)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.
r   rI   2   c                      g r   r-   r-   r   r   r   BMemoryBackedTests.test_tooMuchWorkBeforeStarting.<locals>.<lambda>  r5  r   N)
r&  r6   r   rb   r.  r@   r   rJ   r   rB   r6  s       r   test_tooMuchWorkBeforeStarting0MemoryBackedTests.test_tooMuchWorkBeforeStarting  s     D!R(qA**<8 %%',!%%'V^^,f.?.?.C.CDr   r-   N)r'   r(   r)   r*   r   r:  r@  r,   r-   r   r   r1  r1    s    
1 Er   r1  )r   rf   r   r   r   r`   twisted._threadsr   r   twisted.pythonr   r   r   r   twisted.trialr	   r   synchronizeSynchronousTestCaser/   r   r?   r  r&  r1  r-   r   r   <module>rG     s   
 
     5 C C "! !H    'H1h22 H1V-S55 -S`9&& 9x- -`$E44 $Er   