
    Vhnk                    Z   d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZ ddlmZ ddlmZmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZ ddl m!Z!  ee       G d d             Z" G d dee      Z# G d de!jH                        Z% G d de!jL                        Z'y)z&
Tests for L{twisted.runner.procmon}.
    )annotationsN)AnyStrMappingOptionalSequenceUnion)implementer)ProcessDoneProcessExitedAlreadyProcessTerminated)IProcessProtocolIProcessTransport)Clock)MemoryReactor)globalLogPublisher)Failure)LoggingProtocolProcessMonitor)unittestc                  8    e Zd ZdZdZdZdZ	 	 	 	 ddZd Zd Z	y)DummyProcessa   
    An incomplete and fake L{IProcessTransport} implementation for testing how
    L{ProcessMonitor} behaves when its monitored processes exit.

    @ivar _terminationDelay: the delay in seconds after which the DummyProcess
        will appear to exit when it receives a TERM signal
       Nc                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        y N)
proto_reactor_executable_args_environment_path_uid_gid_usePTY	_childFDs)selfreactor
executableargsenvironmentpathr   uidgidusePTYchildFDss              P/home/dcms/DCMS/lib/python3.12/site-packages/twisted/runner/test/test_procmon.py__init__zDummyProcess.__init__)   sL     
%
'
		!    c                    | j                   dfdd}| j                  
t               ||v r5||   \  }}| j                  j	                  || j
                  |      | _        yy)a  
        A partial implementation of signalProcess which can only handle TERM and
        KILL signals.
         - When a TERM signal is given, the dummy process will appear to exit
           after L{DummyProcess._terminationDelay} seconds with exit code 0
         - When a KILL signal is given, the dummy process will appear to exit
           immediately with exit code 1.

        @param signalID: The signal name or number to be issued to the process.
        @type signalID: C{str}
        r   r   r   )TERMKILLN)_terminationDelaypidr   r   	callLaterprocessEnded_signalHandler)r%   signalIDparamsdelaystatuss        r/   signalProcesszDummyProcess.signalProcessB   sk      1115vF88&((v"8,ME6"&--"9"9t((&#D r1   c                    d| _         t        t        d}| j                  j	                  t         ||   |                   y)zC
        Deliver the process ended event to C{self.proto}.
        Nr3   )r7   r
   r   r   r9   r   )r%   r>   	statusMaps      r/   r9   zDummyProcess.processEndedY   s>      
	 	

(9	&(9&(A BCr1   )NNr   N)
__name__
__module____qualname____doc__r7   r   r6   r0   r?   r9    r1   r/   r   r      s7     CE "2.	Dr1   r   c                  j    e Zd ZU dZded<   ded<   d	dZ	 	 	 	 	 	 d
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)DummyProcessReactorz
    @ivar spawnedProcesses: a list that keeps track of the fake process
        instances built by C{spawnProcess}.

    @ivar spawnProcessException: An exception which spawnProcess() will raise.
    zlist[DummyProcess]spawnedProcesseszException | NonespawnProcessExceptionc                t    t        j                  |        t        j                  |        g | _        d | _        y r   )r   r0   r   rI   rJ   r%   s    r/   r0   zDummyProcessReactor.__init__p   s,    t$t "%)"r1   Nc
                    | j                   | j                   t        | |||||||||	
      }
|j                  |
       | j                  j	                  |
       |
S )zz
        Fake L{reactor.spawnProcess}, that logs all the process
        arguments and returns a L{DummyProcess}.
        )rJ   r   makeConnectionrI   append)r%   processProtocolr'   r(   envr*   r+   r,   r-   r.   procs              r/   spawnProcessz DummyProcessReactor.spawnProcessv   sm      %%1,,,
 	&&t,$$T*r1   returnNone)NNNNFN)rP   r   r'   zUnion[bytes, str]r(   zSequence[Union[bytes, str]]rQ   z!Optional[Mapping[AnyStr, AnyStr]]r*   zUnion[None, bytes, str]r+   Optional[int]r,   rW   r-   boolr.   z'Optional[Mapping[int, Union[int, str]]]rU   r   )rB   rC   rD   rE   __annotations__r0   rS   rF   r1   r/   rH   rH   e   s     )(++* 26(,!!<@!)! &! *	!
 /! &! ! ! ! :! 
!r1   rH   c                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd%dZd%dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%y$)&ProcmonTestsz&
    Tests for L{ProcessMonitor}.
    c                    t               | _        t        | j                        | _        d| j                  _        d| j                  _        d| j                  _        y)zL
        Create an L{ProcessMonitor} wrapped around a fake reactor.
        r&      
   N)rH   r&   r   pmminRestartDelaymaxRestartDelay	thresholdrL   s    r/   setUpzProcmonTests.setUp   sB     +, 6"#"$r1   c                    | j                   j                  dddgddi        t        | j                         }| j                  d|       | j                  d|       | j                  d|       y	)
z+
        Repr includes all details
        fooarg1arg2r   r^   r+   r,   rQ   12N)r`   
addProcessreprassertInr%   representations     r/   test_reprLooksGoodzProcmonTests.test_reprLooksGood   s]     	566"2qbIdgge^,c>*c>*r1   c                    | j                   j                  dddgi        t        | j                         }| j                  d|       | j                  d|       y)z
        Repr does not include unneeded details.

        Values of attributes that just mean "inherit from launching
        process" do not appear in the repr of a process.
        rf   rg   rh   )rQ   ()N)r`   rl   rm   assertNotInro   s     r/   test_simpleReprLooksGoodz%ProcmonTests.test_simpleReprLooksGood   sO     	566"2;dggn-n-r1   c                    | j                   j                  dddgddi        | j                  | j                   j                         d   dddgddi fi       y)	zW
        The list of monitored processes must be included in the pickle state.
        rf   rg   rh   r   r^   ri   	processesN)r`   rl   assertEqual__getstate__rL   s    r/   test_getStateIncludesProcessesz+ProcmonTests.test_getStateIncludesProcesses   s_     	566"2qbIGG  ";/%66:JAqRT9U1V	
r1   c                X    | j                  d| j                  j                                y)z~
        The private L{ProcessMonitor._reactor} instance variable should not be
        included in the pickle state.
        r   N)ru   r`   rz   rL   s    r/   test_getStateExcludesReactorz)ProcmonTests.test_getStateExcludesReactor   s!    
 	TWW%9%9%;<r1   c                   | j                   j                  dddgddi        | j                  | j                   j                  i        | j                  | j                   j                  dddgddi fi       | j                   j                          | j                  j                  d       | j                  t        | j                   j                  j                               dg       y)	z
        L{ProcessMonitor.addProcess} only starts the named program if
        L{ProcessMonitor.startService} has been called.
        rf   rg   rh   r   r^   ri   r   N)
r`   rl   ry   	protocolsrx   startServicer&   advancelistkeysrL   s    r/   test_addProcesszProcmonTests.test_addProcess   s    
 	566"2qbI**B/**Uff5Eq!R4P,QRQdgg//4467%Ar1   c           	         | j                   j                  dddgddi        | j                  t        | j                   j                  dddgddi        y)z|
        L{ProcessMonitor.addProcess} raises a C{KeyError} if a process with the
        given name already exists.
        rf   rg   rh   r   r^   ri   N)r`   rl   assertRaisesKeyErrorrL   s    r/    test_addProcessDuplicateKeyErrorz-ProcmonTests.test_addProcessDuplicateKeyError   sX    
 	566"2qbIdgg((%&&1AqaUW 	 	
r1   c                   ddi}| j                   j                          | j                   j                  ddgdd|       | j                  j	                  d       | j                  | j                  j                  d   j                  |       y)	z
        L{ProcessMonitor.addProcess} takes an C{env} parameter that is passed to
        L{IReactorProcess.spawnProcess}.
        KEYvaluerf   r   r^   ri   r   N)r`   r   rl   r&   r   ry   rI   r   )r%   fakeEnvs     r/   test_addProcessEnvzProcmonTests.test_addProcessEnv   st    
 '"55'qaWEQ66q9FFPr1   c                   | j                   j                          | j                   j                  ddgd       | j                  j	                  d       | j                  | j                  j                  d   j                  d       y)z
        L{ProcessMonitor.addProcess} takes an C{cwd} parameter that is passed
        to L{IReactorProcess.spawnProcess}.
        rf   z	/mnt/lala)cwdr   N)r`   r   rl   r&   r   ry   rI   r    rL   s    r/   test_addProcessCwdzProcmonTests.test_addProcessCwd   sf    
 	55'{;Q66q9??Mr1   c                d   | j                   j                          | j                   j                  ddg       | j                  t	        | j                   j
                        d       | j                   j                  d       | j                  t	        | j                   j
                        d       y)zm
        L{ProcessMonitor.removeProcess} removes the process from the public
        processes list.
        rf   r   r   N)r`   r   rl   ry   lenrx   removeProcessrL   s    r/   test_removeProcesszProcmonTests.test_removeProcess   sz    
 	55'*TWW../3e$TWW../3r1   c                    | j                   j                          | j                  t        | j                   j                  d       y)zz
        L{ProcessMonitor.removeProcess} raises a C{KeyError} if the given
        process name isn't recognised.
        rf   N)r`   r   r   r   r   rL   s    r/   !test_removeProcessUnknownKeyErrorz.ProcmonTests.test_removeProcessUnknownKeyError  s0    
 	(DGG$9$95Ar1   c                6   | j                   j                  ddg       | j                   j                  d       | j                  | j                   j                  d   t
               | j                  d| j                   j                  j                                y)a  
        When a process has been started, an instance of L{LoggingProtocol} will
        be added to the L{ProcessMonitor.protocols} dict and the start time of
        the process will be recorded in the L{ProcessMonitor.timeStarted}
        dictionary.
        rf   N)	r`   rl   startProcessassertIsInstancer   r   rn   timeStartedr   rL   s    r/   test_startProcesszProcmonTests.test_startProcess  sl     	55'*U#dgg//6HeTWW005578r1   c                    | j                   j                  ddg       | j                   j                  d       | j                  | j                   j                  d             y)zr
        L{ProcessMonitor.startProcess} silently returns if the named process is
        already started.
        rf   N)r`   rl   r   assertIsNonerL   s    r/   test_startProcessAlreadyStartedz,ProcmonTests.test_startProcessAlreadyStarted  sI    
 	55'*U#$''..u56r1   c                Z    | j                  t        | j                  j                  d       y)zy
        L{ProcessMonitor.startProcess} raises a C{KeyError} if the given
        process name isn't recognised.
        rf   N)r   r   r`   r   rL   s    r/    test_startProcessUnknownKeyErrorz-ProcmonTests.test_startProcessUnknownKeyError"  s     
 	(DGG$8$8%@r1   c                   t        t        j                  t        j                  t        j                              | j
                  _        d| j                  _        d| j                  _	        | j                  j                  ddg       | j                  j                  d       | j                  | j                  j                  d   d       | j                  t        | j                  t                     d       y)z
        L{IReactorProcess.spawnProcess} might raise C{OSError}, ensure it
        is caught and process is restarted.
        {   rf   r   N)OSErrorerrnoEAGAINosstrerrorr&   rJ   r`   ra   rb   rl   r   assertEqualsr=   r   flushLoggedErrorsrL   s    r/   %test_startProcessSpawnCaughtExceptionz2ProcmonTests.test_startProcessSpawnCaughtException)  s    
 .5LL"++ell3.
* #&"%55'*U#$''--.4#d44W=>Br1   c                    t        d      | j                  _        | j                  j	                  ddg       | j                  t         | j                  j                  d       y)zy
        L{IReactorProcess.spawnProcess} might raise C{OSError}, ensure other
        exceptions are not caught.
        zJust another exceptionrf   N)SystemErrorr&   rJ   r`   rl   r   r   rL   s    r/   'test_startProcessSpawnUncaughtExceptionz4ProcmonTests.test_startProcessSpawnUncaughtException9  sH    
 .99Q-R*55'*+tww';';UCr1   c                   | j                   j                          | j                   j                  ddg       | j                  d| j                   j                         dx}| j                   j                  d   j
                  _        | j                  j                  | j                   j                         | j                   j                  d       | j                  j                  |       | j                  j                  d       | j                  | j                  j                         | j                   j                  d          y)zm
        L{ProcessMonitor.stopProcess} immediately sends a TERM signal to the
        named process.
        rf   r   r   N)r`   r   rl   rn   r   	transportr6   r&   r   rc   stopProcessry   secondsr   )r%   	timeToDies     r/   "test_stopProcessNaturalTerminationz/ProcmonTests.test_stopProcessNaturalTerminationB  s    
 	55'*eTWW../ LML	DGG%%e,66H 	TWW../E" 	Y'
 	Q 	--/1D1DU1KLr1   c                |   | j                   j                          | j                   j                  ddg       | j                  d| j                   j                         | j
                  j                  | j                   j                         | j                   j                  d   j                  }| j                   j                  dz   |_
        | j                   j                  d       | j
                  j                  | j                   j                  dz
         | j                  d| j                   j                  d          | j
                  j                  d       | j
                  j                  ddg       | j                  | j
                  j                         | j                   j                  d          y)z
        L{ProcessMonitor.stopProcess} kills a process which fails to terminate
        naturally within L{ProcessMonitor.killTime} seconds.
        rf   r   g        r   N)r`   r   rl   rn   r   r&   r   rc   r   killTimer6   r   ry   r   pumpr   )r%   rR   s     r/   test_stopProcessForcedKillz'ProcmonTests.test_stopProcessForcedKill`  s9   
 	55'*eTWW../TWW../ww  '11!%!1!1A!5E" 	TWW--12dgg11%89Q 	1a&!--/1D1DU1KLr1   c                Z    | j                  t        | j                  j                  d       y)zx
        L{ProcessMonitor.stopProcess} raises a C{KeyError} if the given process
        name isn't recognised.
        rf   N)r   r   r`   r   rL   s    r/   test_stopProcessUnknownKeyErrorz,ProcmonTests.test_stopProcessUnknownKeyError}  s     
 	(DGG$7$7?r1   c                    | j                   j                  ddg       | j                  | j                   j                  d             y)z
        L{ProcessMonitor.stopProcess} silently returns if the named process
        is already stopped. eg Process has crashed and a restart has been
        rescheduled, but in the meantime, the service is stopped.
        rf   N)r`   rl   r   r   rL   s    r/   test_stopProcessAlreadyStoppedz+ProcmonTests.test_stopProcessAlreadyStopped  s7     	55'*$''--e45r1   c                >   g }| j                  t        j                  |j                         t        j                  |j                         | j
                  j                  ddg       | j
                  j                          | j                  j                  d       | j                  d| j
                  j                         | j                  j                  | j
                  j                         | j
                  j                  d   j                  d       | j                  t        |      d       |d   d   }|d   d   }|d   d   }|d   d   }| j                  |d	       | j                  |d
       | j                  |d       | j                  |d       y)zS
        Getting a complete output line on stdout generates a log message.
        rf   r      hello world!
r   log_namespacestreamtagline%twisted.runner.procmon.ProcessMonitorstdouthello world!N)
addCleanupr   removeObserverrO   addObserverr`   rl   r   r&   r   rn   r   rc   outReceivedr   r   r%   events	namespacer   r   r   s         r/   test_outputReceivedCompleteLinez,ProcmonTests.test_outputReceivedCompleteLine  K    *996==I&&v}}555'*QeTWW../TWW../% ,,->?#f+q)1Io.	8$Qiay )%LM&(+#u%$/r1   c                >   g }| j                  t        j                  |j                         t        j                  |j                         | j
                  j                  ddg       | j
                  j                          | j                  j                  d       | j                  d| j
                  j                         | j                  j                  | j
                  j                         | j
                  j                  d   j                  d       | j                  t        |      d       |d   d   }|d   d   }|d   d   }|d   d   }| j                  |d	       | j                  |d
       | j                  |d       | j                  |d       y)zS
        Getting a complete output line on stderr generates a log message.
        rf   r   r   r   r   r   r   r   r   stderrr   N)r   r   r   rO   r   r`   rl   r   r&   r   rn   r   rc   errReceivedr   r   r   s         r/   !test_ouputReceivedCompleteErrLinez.ProcmonTests.test_ouputReceivedCompleteErrLine  r   r1   c                B   g }| j                  t        j                  |j                         t        j                  |j                         | j
                  j                  ddg       | j
                  j                          | j                  j                  d       | j                  d| j
                  j                         | j                  j                  | j
                  j                         | j
                  j                  d   j                  d       | j                  t        |      d       |d   }|d   }|d   }|d   }|d   }| j                  |d	       | j                  |d
       | j                  |d       | j                  |t!        d             y)zN
        Getting invalid UTF-8 results in the repr of the raw message
        rf   r   s   hello world!
r   r   r   r   r   r   r   s   hello world!N)r   r   r   rO   r   r`   rl   r   r&   r   rn   r   rc   r   r   r   rm   )r%   r   messager   r   r   outputs          r/   *test_outputReceivedCompleteLineInvalidUTF8z7ProcmonTests.test_outputReceivedCompleteLineInvalidUTF8  sH    *996==I&&v}}555'*QeTWW../TWW../% ,,-BC#f+q))O,	"en)%LM&(+#u%&$':";<r1   c                   g }| j                  t        j                  |j                         t        j                  |j                         | j
                  j                  ddg       | j
                  j                          | j                  j                  d       | j                  d| j
                  j                         | j                  j                  | j
                  j                         | j
                  j                  d   j                  d       | j                  t        |      d       | j
                  j                  d   j!                  t#        t%        d                   | j                  t        |      d       |d   d   }|d   d   }|d   d   }|d   d   }| j                  |d	       | j                  |d
       | j                  |d       | j                  |d       y)zM
        Getting partial line results in no events until process end
        rf   r   s   hello world!r   r   r   r   r   r   r   r   N)r   r   r   rO   r   r`   rl   r   r&   r   rn   r   rc   r   r   r   r9   r   r
   r   s         r/   test_outputReceivedPartialLinez+ProcmonTests.test_outputReceivedPartialLine  s    *996==I&&v}}555'*QeTWW../TWW../% ,,_=#f+q)% --gk!n.EF#f+q)1Io.	8$Qiay )%LM&(+#u%$/r1   c                   | j                   j                  ddg       | j                   j                          | j                  j	                  d       | j                  d| j                   j                         | j                  j	                  | j                   j                         | j                   j                  d   j                  t        t        d                   | j                  d| j                   j                         | j                  j	                  d       | j                  d| j                   j                         y)z
        L{ProcessMonitor.processExit} should immediately restart a process
        if it has been running longer than L{ProcessMonitor.threshold} seconds.
        rf   r   N)r`   rl   r   r&   r   rn   r   rc   r9   r   r
   ru   rL   s    r/   #test_connectionLostLongLivedProcessz0ProcmonTests.test_connectionLostLongLivedProcess  s    
 	55'*QeTWW../TWW../% --gk!n.EF 1 12QeTWW../r1   c                   | j                   j                  ddg       | j                   j                          | j                  j	                  d       | j                   j                  d       | j                  d| j                   j                         | j                   j                  d   }| j                  |j                                | j                  j	                  | j                   j                  d   j                  j                         | j                  |j                                | j                  d| j                   j                         y)z
        L{ProcessMonitor.processExit} cancels a scheduled process killer and
        deletes the DelayedCall from the L{ProcessMonitor.murder} list.
        rf   r   N)r`   rl   r   r&   r   r   rn   murder
assertTrueactiver   r   r6   assertFalseru   )r%   delayedCalls     r/   test_connectionLostMurderCancelz,ProcmonTests.test_connectionLostMurderCancel  s    
 	55'*QE"eTWW^^,ggnnU+**,-TWW..u5??QQR++-./r1   c                   | j                   j                          | j                   j                  ddg       | j                  d| j                   j                         | j                   j                  d   j
                  j                  d       | j                  j                  | j                   j                  d   j
                  j                         | j                  d| j                   j                         y)z
        L{ProcessMonitor.processExit} removes the corresponding
        ProcessProtocol instance from the L{ProcessMonitor.protocols} list.
        rf   r5   N)r`   r   rl   rn   r   r   r?   r&   r   r6   ru   rL   s    r/   #test_connectionLostProtocolDeletionz0ProcmonTests.test_connectionLostProtocolDeletion%  s    
 	55'*eTWW../% **88@TWW..u5??QQR 1 12r1   c                   d| j                   _        d| j                   _        | j                   j                          | j                   j	                  ddg       | j                  | j                   j                  d   | j                   j                         | j                  j                  | j                   j                  dz
         | j                   j                  d   j                  t        t        d                   | j                  | j                   j                  d   | j                   j                         y)zz
        L{ProcessMonitor.processExit} will wait at least minRestartDelay s
        and at most maxRestartDelay s
        r^      rf   r   r   N)r`   ra   rb   r   rl   ry   r=   r&   r   rc   r   r9   r   r
   rL   s    r/   %test_connectionLostMinMaxRestartDelayz2ProcmonTests.test_connectionLostMinMaxRestartDelay1  s    
 #$"#55'*u-tww/F/FGTWW..23% --gk!n.EFu-tww/F/FGr1   c                   | j                   j                          | j                   j                  ddg       | j                  j	                  | j                   j
                  dz
         | j                  d| j                   j                         | j                  | j                   j                  d   | j                   j                         | j                   j                  d   j                  t        t        d                   | j                  | j                   j                  d   | j                   j                  dz         y)zy
        L{ProcessMonitor.processExit} doubles the restart delay each time
        the process dies too quickly.
        rf   r   r   r^   N)r`   r   rl   r&   r   rc   rn   r   ry   r=   ra   r9   r   r
   rL   s    r/   &test_connectionLostBackoffDelayDoublesz3ProcmonTests.test_connectionLostBackoffDelayDoublesA  s    
 	55'*TWW..23eTWW../u-tww/F/FG% --gk!n.EFu-tww/F/F/JKr1   c                    | j                   j                  ddg       | j                   j                          | j                  j	                  d       | j                  d| j                   j                         y)zP
        L{ProcessMonitor.startService} starts all monitored processes.
        rf   r   N)r`   rl   r   r&   r   rn   r   rL   s    r/   test_startServicezProcmonTests.test_startServiceO  sT     	55'*QeTWW../r1   c                   | j                   j                  ddg       | j                   j                  ddg       | j                   j                          | j                  j	                  | j                   j
                         | j                  d| j                   j                         | j                  d| j                   j                         | j                  j	                  d       | j                   j                          | j                  j	                  | j                   j                  dz          | j                  i | j                   j                         y)zT
        L{ProcessMonitor.stopService} should stop all monitored processes.
        rf   barr   N)r`   rl   r   r&   r   rc   rn   r   stopServicer   ry   rL   s    r/   test_stopServicezProcmonTests.test_stopServiceZ  s     	55'*55'*TWW../eTWW../eTWW../Q 	TWW--12TWW../r1   c                   | j                   j                  ddg       | j                   j                          | j                  j	                  d       | j                   j                          | j                  j	                  d       t        | j                  j                        }|j                         }| j                  |g        | j                  |j                         y)zR
        L{ProcessMonitor.restartAll} succeeds when there is one process.
        rf   r   N)r`   rl   r   r&   r   
restartAllr   rI   popr   r   r7   )r%   rx   	myProcesss      r/   !test_restartAllRestartsOneProcessz.ProcmonTests.test_restartAllRestartsOneProcessp  s     	55'*Q 	Q667	MMO	)R()--(r1   c                   | j                   j                  ddg       | j                   j                          | j                  j	                  | j                   j
                         | j                  d| j                   j                         | j                  j	                  d       | j                   j                  d   j                  t        t        d                   | j                  | j                   j                  d   j                                | j                   j                          | j                  | j                   j                  d   j                                y)ze
        L{ProcessMonitor.stopService} should cancel any scheduled process
        restarts.
        rf   r   r   N)r`   rl   r   r&   r   rc   rn   r   r9   r   r
   r   restartr   r   r   rL   s    r/   test_stopServiceCancelRestartsz+ProcmonTests.test_stopServiceCancelRestarts  s    
 	55'*TWW../eTWW../Q% --gk!n.EF.5578/6689r1   c                   d| j                   _        d| j                   _        | j                   j                          | j                   j	                  ddg       | j
                  j                  d       | j                   j                  d       | j
                  j                  d       | j                   j                          | j
                  j                  d       | j                  | j                   j                  i        y)ze
        L{ProcessMonitor.stopService} should cancel all scheduled process
        restarts.
           rf   r      N)r`   rc   ra   r   rl   r&   r   r   r   ry   r   rL   s    r/   (test_stopServiceCleanupScheduledRestartsz5ProcmonTests.test_stopServiceCleanupScheduledRestarts  s    
 "#55'*QE"QQ 	**B/r1   NrT   )&rB   rC   rD   rE   rd   rq   rv   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r1   r/   r[   r[      s    +
.
=
B
	QN	4B
97AC DM<M:@60606=80:0(0*
3H L	00,) :(0r1   r[   c                  (    e Zd ZdZd Zd Zd Zd Zy)DeprecationTestszQ
    Tests that check functionality that should be deprecated is deprecated.
    c                X    t               | _        t        | j                        | _        y)z5
        Create reactor and process monitor.
        r]   N)rH   r&   r   r`   rL   s    r/   rd   zDeprecationTests.setUp  s     +, 6r1   c                T   | j                   j                  ddg       | j                   j                  }| j                  t	        |      d       | j                         }d}|D ]%  }| j                  |d   t               d|d   v s$d}' | j                  |dt        |              y	)
a   
        _Process.toTuple is deprecated.

        When getting the deprecated processes property, the actual
        data (kept in the class _Process) is converted to a tuple --
        which produces a DeprecationWarning per process so converted.
        rf   r   FcategorytoTupler   Tzno tuple deprecation found:N)
r`   rl   rx   r   r   flushWarningsassertIsDeprecationWarningr   rm   )r%   myprocesseswarningsfoundToTuplewarnings        r/   test_toTuplezDeprecationTests.test_toTuple  s     	55'*gg''#k*A.%%' 	$GMM'*-/ABGI..#	$ 	(CDNCS&TUr1   c                    | j                   j                  }| j                  |i        | j                         }|j	                  d      }| j                  |d   t               | j                  |g        y)a  
        Accessing L{ProcessMonitor.processes} results in deprecation warning

        Even when there are no processes, and thus no process is converted
        to a tuple, accessing the L{ProcessMonitor.processes} property
        should generate its own DeprecationWarning.
        r   r   N)r`   rx   r   r   r   r  r  )r%   myProcessesr  firsts       r/   test_processeszDeprecationTests.test_processes  sb     gg''+r*%%'QeJ');<(B'r1   c                    t        j                  | j                         | j                         }|D ]  }| j	                  |d   t
                y)zO
        Pickling an L{ProcessMonitor} results in deprecation warnings
        r   N)pickledumpsr`   r   r  r  )r%   r  r  s      r/   test_getstatezDeprecationTests.test_getstate  sG     	TWW%%' 	CGMM'*-/AB	Cr1   N)rB   rC   rD   rE   rd   r  r  r  rF   r1   r/   r   r     s    7V&(Cr1   r   )(rE   
__future__r   r   r   r  typingr   r   r   r   r   zope.interfacer	   twisted.internet.errorr
   r   r   twisted.internet.interfacesr   r   twisted.internet.taskr   twisted.internet.testingr   twisted.loggerr   twisted.python.failurer   twisted.runner.procmonr   r   twisted.trialr   r   rH   TestCaser[   SynchronousTestCaser   rF   r1   r/   <module>r     s    #  	  = = & W W K ' 2 - * B " GD GD  GDT2- 2jO08$$ O0d5Cx33 5Cr1   