@@ -812,31 +812,26 @@ def test_kill_nopid(self):
812812 'attempted to kill test with sig SIGTERM but it wasn\' t running' )
813813 self .assertFalse (instance .killing )
814814
815- def test_kill_error (self ):
815+ def test_kill_from_starting (self ):
816816 options = DummyOptions ()
817817 config = DummyPConfig (options , 'test' , '/test' )
818- options .kill_exception = OSError (errno .EPERM )
819818 instance = self ._makeOne (config )
819+ instance .pid = 11
820820 L = []
821821 from supervisor .states import ProcessStates
822822 from supervisor import events
823823 events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
824- instance .pid = 11
825- instance .state = ProcessStates .RUNNING
824+ instance .state = ProcessStates .STARTING
826825 instance .kill (signal .SIGTERM )
827826 self .assertEqual (options .logger .data [0 ], 'killing test (pid 11) with '
828827 'signal SIGTERM' )
829- self .assertTrue (options .logger .data [1 ].startswith (
830- 'unknown problem killing test' ))
831- self .assertTrue ('Traceback' in options .logger .data [1 ])
832- self .assertFalse (instance .killing )
833- self .assertEqual (len (L ), 2 )
834- event1 = L [0 ]
835- event2 = L [1 ]
836- self .assertEqual (event1 .__class__ , events .ProcessStateStoppingEvent )
837- self .assertEqual (event2 .__class__ , events .ProcessStateUnknownEvent )
828+ self .assertTrue (instance .killing )
829+ self .assertEqual (options .kills [11 ], signal .SIGTERM )
830+ self .assertEqual (len (L ), 1 )
831+ event = L [0 ]
832+ self .assertEqual (event .__class__ , events .ProcessStateStoppingEvent )
838833
839- def test_kill_from_starting (self ):
834+ def test_kill_from_running (self ):
840835 options = DummyOptions ()
841836 config = DummyPConfig (options , 'test' , '/test' )
842837 instance = self ._makeOne (config )
@@ -845,7 +840,7 @@ def test_kill_from_starting(self):
845840 from supervisor .states import ProcessStates
846841 from supervisor import events
847842 events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
848- instance .state = ProcessStates .STARTING
843+ instance .state = ProcessStates .RUNNING
849844 instance .kill (signal .SIGTERM )
850845 self .assertEqual (options .logger .data [0 ], 'killing test (pid 11) with '
851846 'signal SIGTERM' )
@@ -855,24 +850,31 @@ def test_kill_from_starting(self):
855850 event = L [0 ]
856851 self .assertEqual (event .__class__ , events .ProcessStateStoppingEvent )
857852
858- def test_kill_from_running (self ):
853+ def test_kill_from_running_error (self ):
859854 options = DummyOptions ()
860855 config = DummyPConfig (options , 'test' , '/test' )
856+ options .kill_exception = OSError (errno .EPERM )
861857 instance = self ._makeOne (config )
862- instance .pid = 11
863858 L = []
864859 from supervisor .states import ProcessStates
865860 from supervisor import events
866861 events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
862+ instance .pid = 11
867863 instance .state = ProcessStates .RUNNING
868864 instance .kill (signal .SIGTERM )
869865 self .assertEqual (options .logger .data [0 ], 'killing test (pid 11) with '
870866 'signal SIGTERM' )
871- self .assertTrue (instance .killing )
872- self .assertEqual (options .kills [11 ], signal .SIGTERM )
873- self .assertEqual (len (L ), 1 )
874- event = L [0 ]
875- self .assertEqual (event .__class__ , events .ProcessStateStoppingEvent )
867+ self .assertTrue (options .logger .data [1 ].startswith (
868+ 'unknown problem killing test' ))
869+ self .assertTrue ('Traceback' in options .logger .data [1 ])
870+ self .assertFalse (instance .killing )
871+ self .assertEqual (instance .pid , 0 )
872+ self .assertEqual (instance .state , ProcessStates .UNKNOWN )
873+ self .assertEqual (len (L ), 2 )
874+ event1 = L [0 ]
875+ event2 = L [1 ]
876+ self .assertEqual (event1 .__class__ , events .ProcessStateStoppingEvent )
877+ self .assertEqual (event2 .__class__ , events .ProcessStateUnknownEvent )
876878
877879 def test_kill_from_stopping (self ):
878880 options = DummyOptions ()
@@ -945,7 +947,7 @@ def test_stopasgroup(self):
945947 self .assertEqual (event .extra_values , [('pid' , 11 )])
946948 self .assertEqual (event .from_state , ProcessStates .RUNNING )
947949
948- def test_signal (self ):
950+ def test_signal_from_stopped (self ):
949951 options = DummyOptions ()
950952
951953 killedpid = []
@@ -955,23 +957,23 @@ def kill(pid, sig):
955957 killedpid .append (pid )
956958 killedsig .append (sig )
957959
958- options .kill = kill
960+ options .kill = kill #don't actually start killing random processes...
959961
960962 config = DummyPConfig (options , 'test' , '/test' )
961963 instance = self ._makeOne (config )
962- instance .pid = 11
964+ instance .pid = None
963965
964966 from supervisor .states import ProcessStates
965- instance .state = ProcessStates .RUNNING
967+ instance .state = ProcessStates .STOPPED
966968
967969 instance .signal (signal .SIGWINCH )
968970
969- self .assertEqual (killedpid , [ instance . pid ,])
970- self . assertEqual ( killedsig , [ signal . SIGWINCH ,] )
971+ self .assertEqual (options . logger . data [ 0 ], "attempted to send test sig SIGWINCH "
972+ "but it wasn't running" )
971973
972- self .assertEqual (options . logger . data [ 0 ], 'sending test (pid 11) sig SIGWINCH' )
974+ self .assertEqual (killedpid , [] )
973975
974- def test_signal_stopped (self ):
976+ def test_signal_from_running (self ):
975977 options = DummyOptions ()
976978
977979 killedpid = []
@@ -981,23 +983,23 @@ def kill(pid, sig):
981983 killedpid .append (pid )
982984 killedsig .append (sig )
983985
984- options .kill = kill #don't actually start killing random processes...
986+ options .kill = kill
985987
986988 config = DummyPConfig (options , 'test' , '/test' )
987989 instance = self ._makeOne (config )
988- instance .pid = None
990+ instance .pid = 11
989991
990992 from supervisor .states import ProcessStates
991- instance .state = ProcessStates .STOPPED
993+ instance .state = ProcessStates .RUNNING
992994
993995 instance .signal (signal .SIGWINCH )
994996
995- self .assertEqual (options . logger . data [ 0 ], "attempted to send test sig SIGWINCH "
996- "but it wasn't running" )
997+ self .assertEqual (killedpid , [ instance . pid ,])
998+ self . assertEqual ( killedsig , [ signal . SIGWINCH ,] )
997999
998- self .assertEqual (killedpid , [] )
1000+ self .assertEqual (options . logger . data [ 0 ], 'sending test (pid 11) sig SIGWINCH' )
9991001
1000- def test_signal_error (self ):
1002+ def test_signal_from_running_error (self ):
10011003 options = DummyOptions ()
10021004 config = DummyPConfig (options , 'test' , '/test' )
10031005 options .kill_exception = OSError (errno .EPERM )
@@ -1015,6 +1017,8 @@ def test_signal_error(self):
10151017 'unknown problem sending sig test (11)' ))
10161018 self .assertTrue ('Traceback' in options .logger .data [1 ])
10171019 self .assertFalse (instance .killing )
1020+ self .assertEqual (instance .state , ProcessStates .UNKNOWN )
1021+ self .assertEqual (instance .pid , 0 )
10181022 self .assertEqual (len (L ), 1 )
10191023 event = L [0 ]
10201024 self .assertEqual (event .__class__ , events .ProcessStateUnknownEvent )
0 commit comments