@@ -898,24 +898,24 @@ def test_stopasgroup(self):
898
898
self .assertEqual (event .extra_values , [('pid' , 11 )])
899
899
self .assertEqual (event .from_state , ProcessStates .RUNNING )
900
900
901
- def test_finish (self ):
901
+ def test_finish_stopping_state (self ):
902
902
options = DummyOptions ()
903
903
config = DummyPConfig (options , 'notthere' , '/notthere' ,
904
904
stdout_logfile = '/tmp/foo' )
905
905
instance = self ._makeOne (config )
906
906
instance .waitstatus = (123 , 1 ) # pid, waitstatus
907
907
instance .config .options .pidhistory [123 ] = instance
908
- instance .killing = 1
908
+ instance .killing = True
909
909
pipes = {'stdout' :'' ,'stderr' :'' }
910
910
instance .pipes = pipes
911
911
from supervisor .states import ProcessStates
912
912
from supervisor import events
913
913
instance .state = ProcessStates .STOPPING
914
914
L = []
915
- events .subscribe (events .ProcessStateStoppedEvent , lambda x : L .append (x ))
915
+ events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
916
916
instance .pid = 123
917
917
instance .finish (123 , 1 )
918
- self .assertEqual (instance .killing , 0 )
918
+ self .assertFalse (instance .killing )
919
919
self .assertEqual (instance .pid , 0 )
920
920
self .assertEqual (options .parent_pipes_closed , pipes )
921
921
self .assertEqual (instance .pipes , {})
@@ -929,7 +929,7 @@ def test_finish(self):
929
929
self .assertEqual (event .extra_values , [('pid' , 123 )])
930
930
self .assertEqual (event .from_state , ProcessStates .STOPPING )
931
931
932
- def test_finish_expected (self ):
932
+ def test_finish_running_state_exit_expected (self ):
933
933
options = DummyOptions ()
934
934
config = DummyPConfig (options , 'notthere' , '/notthere' ,
935
935
stdout_logfile = '/tmp/foo' )
@@ -942,10 +942,10 @@ def test_finish_expected(self):
942
942
from supervisor import events
943
943
instance .state = ProcessStates .RUNNING
944
944
L = []
945
- events .subscribe (events .ProcessStateExitedEvent , lambda x : L .append (x ))
945
+ events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
946
946
instance .pid = 123
947
947
instance .finish (123 , 1 )
948
- self .assertEqual (instance .killing , 0 )
948
+ self .assertFalse (instance .killing )
949
949
self .assertEqual (instance .pid , 0 )
950
950
self .assertEqual (options .parent_pipes_closed , pipes )
951
951
self .assertEqual (instance .pipes , {})
@@ -961,7 +961,48 @@ def test_finish_expected(self):
961
961
self .assertEqual (event .extra_values , [('expected' , True ), ('pid' , 123 )])
962
962
self .assertEqual (event .from_state , ProcessStates .RUNNING )
963
963
964
- def test_finish_tooquickly (self ):
964
+ def test_finish_starting_state_laststart_in_future (self ):
965
+ options = DummyOptions ()
966
+ config = DummyPConfig (options , 'notthere' , '/notthere' ,
967
+ stdout_logfile = '/tmp/foo' )
968
+ instance = self ._makeOne (config )
969
+ instance .config .options .pidhistory [123 ] = instance
970
+ pipes = {'stdout' :'' ,'stderr' :'' }
971
+ instance .pipes = pipes
972
+ instance .config .exitcodes = [- 1 ]
973
+ instance .laststart = time .time () + 3600 # 1 hour into the future
974
+ from supervisor .states import ProcessStates
975
+ from supervisor import events
976
+ instance .state = ProcessStates .STARTING
977
+ L = []
978
+ events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
979
+ instance .pid = 123
980
+ instance .finish (123 , 1 )
981
+ self .assertFalse (instance .killing )
982
+ self .assertEqual (instance .pid , 0 )
983
+ self .assertEqual (options .parent_pipes_closed , pipes )
984
+ self .assertEqual (instance .pipes , {})
985
+ self .assertEqual (instance .dispatchers , {})
986
+ self .assertEqual (options .logger .data [0 ],
987
+ "process 'notthere' (123) laststart time is in the "
988
+ "future, don't know how long process was running so "
989
+ "assuming it did not exit too quickly" )
990
+ self .assertEqual (options .logger .data [1 ],
991
+ 'exited: notthere (terminated by SIGHUP; expected)' )
992
+ self .assertEqual (instance .exitstatus , - 1 )
993
+ self .assertEqual (len (L ), 2 )
994
+ event = L [0 ]
995
+ self .assertEqual (event .__class__ , events .ProcessStateRunningEvent )
996
+ self .assertEqual (event .expected , True )
997
+ self .assertEqual (event .extra_values , [('pid' , 123 )])
998
+ self .assertEqual (event .from_state , ProcessStates .STARTING )
999
+ event = L [1 ]
1000
+ self .assertEqual (event .__class__ , events .ProcessStateExitedEvent )
1001
+ self .assertEqual (event .expected , True )
1002
+ self .assertEqual (event .extra_values , [('expected' , True ), ('pid' , 123 )])
1003
+ self .assertEqual (event .from_state , ProcessStates .RUNNING )
1004
+
1005
+ def test_finish_starting_state_exited_too_quickly (self ):
965
1006
options = DummyOptions ()
966
1007
config = DummyPConfig (options , 'notthere' , '/notthere' ,
967
1008
stdout_logfile = '/tmp/foo' , startsecs = 10 )
@@ -970,7 +1011,6 @@ def test_finish_tooquickly(self):
970
1011
pipes = {'stdout' :'' ,'stderr' :'' }
971
1012
instance .pipes = pipes
972
1013
instance .config .exitcodes = [- 1 ]
973
- import time
974
1014
instance .laststart = time .time ()
975
1015
from supervisor .states import ProcessStates
976
1016
from supervisor import events
@@ -979,7 +1019,7 @@ def test_finish_tooquickly(self):
979
1019
events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
980
1020
instance .pid = 123
981
1021
instance .finish (123 , 1 )
982
- self .assertEqual (instance .killing , 0 )
1022
+ self .assertFalse (instance .killing )
983
1023
self .assertEqual (instance .pid , 0 )
984
1024
self .assertEqual (options .parent_pipes_closed , pipes )
985
1025
self .assertEqual (instance .pipes , {})
@@ -992,6 +1032,43 @@ def test_finish_tooquickly(self):
992
1032
self .assertEqual (event .__class__ , events .ProcessStateBackoffEvent )
993
1033
self .assertEqual (event .from_state , ProcessStates .STARTING )
994
1034
1035
+ def test_finish_running_state_laststart_in_future (self ):
1036
+ options = DummyOptions ()
1037
+ config = DummyPConfig (options , 'notthere' , '/notthere' ,
1038
+ stdout_logfile = '/tmp/foo' )
1039
+ instance = self ._makeOne (config )
1040
+ instance .config .options .pidhistory [123 ] = instance
1041
+ pipes = {'stdout' :'' ,'stderr' :'' }
1042
+ instance .pipes = pipes
1043
+ instance .config .exitcodes = [- 1 ]
1044
+ instance .laststart = time .time () + 3600 # 1 hour into the future
1045
+ from supervisor .states import ProcessStates
1046
+ from supervisor import events
1047
+ instance .state = ProcessStates .RUNNING
1048
+ L = []
1049
+ events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
1050
+ instance .pid = 123
1051
+ instance .finish (123 , 1 )
1052
+ self .assertFalse (instance .killing )
1053
+ self .assertEqual (instance .pid , 0 )
1054
+ self .assertEqual (options .parent_pipes_closed , pipes )
1055
+ self .assertEqual (instance .pipes , {})
1056
+ self .assertEqual (instance .dispatchers , {})
1057
+ self .assertEqual (options .logger .data [0 ],
1058
+ "process 'notthere' (123) laststart time is in the "
1059
+ "future, don't know how long process was running so "
1060
+ "assuming it did not exit too quickly" )
1061
+ self .assertEqual (options .logger .data [1 ],
1062
+ 'exited: notthere (terminated by SIGHUP; expected)' )
1063
+ self .assertEqual (instance .exitstatus , - 1 )
1064
+ self .assertEqual (len (L ), 1 )
1065
+ event = L [0 ]
1066
+ self .assertEqual (event .__class__ ,
1067
+ events .ProcessStateExitedEvent )
1068
+ self .assertEqual (event .expected , True )
1069
+ self .assertEqual (event .extra_values , [('expected' , True ), ('pid' , 123 )])
1070
+ self .assertEqual (event .from_state , ProcessStates .RUNNING )
1071
+
995
1072
def test_finish_with_current_event_sends_rejected (self ):
996
1073
from supervisor import events
997
1074
L = []
0 commit comments