@@ -1140,6 +1140,43 @@ def test_finish_starting_state_exited_too_quickly(self):
1140
1140
self .assertEqual (event .__class__ , events .ProcessStateBackoffEvent )
1141
1141
self .assertEqual (event .from_state , ProcessStates .STARTING )
1142
1142
1143
+ # This tests the case where the process has stayed alive longer than
1144
+ # startsecs (i.e., long enough to enter the RUNNING state), however the
1145
+ # system clock has since rolled backward such that the current time is
1146
+ # greater than laststart but less than startsecs.
1147
+ def test_finish_running_state_exited_too_quickly_due_to_clock_rollback (self ):
1148
+ options = DummyOptions ()
1149
+ config = DummyPConfig (options , 'notthere' , '/notthere' ,
1150
+ stdout_logfile = '/tmp/foo' , startsecs = 10 )
1151
+ instance = self ._makeOne (config )
1152
+ instance .config .options .pidhistory [123 ] = instance
1153
+ pipes = {'stdout' :'' ,'stderr' :'' }
1154
+ instance .pipes = pipes
1155
+ instance .config .exitcodes = [- 1 ]
1156
+ instance .laststart = time .time ()
1157
+ from supervisor .states import ProcessStates
1158
+ from supervisor import events
1159
+ instance .state = ProcessStates .RUNNING
1160
+ L = []
1161
+ events .subscribe (events .ProcessStateEvent , lambda x : L .append (x ))
1162
+ instance .pid = 123
1163
+ instance .finish (123 , 1 )
1164
+ self .assertFalse (instance .killing )
1165
+ self .assertEqual (instance .pid , 0 )
1166
+ self .assertEqual (options .parent_pipes_closed , pipes )
1167
+ self .assertEqual (instance .pipes , {})
1168
+ self .assertEqual (instance .dispatchers , {})
1169
+ self .assertEqual (options .logger .data [0 ],
1170
+ 'exited: notthere (terminated by SIGHUP; expected)' )
1171
+ self .assertEqual (instance .exitstatus , - 1 )
1172
+ self .assertEqual (len (L ), 1 )
1173
+ event = L [0 ]
1174
+ self .assertEqual (event .__class__ ,
1175
+ events .ProcessStateExitedEvent )
1176
+ self .assertEqual (event .expected , True )
1177
+ self .assertEqual (event .extra_values , [('expected' , True ), ('pid' , 123 )])
1178
+ self .assertEqual (event .from_state , ProcessStates .RUNNING )
1179
+
1143
1180
def test_finish_running_state_laststart_in_future (self ):
1144
1181
options = DummyOptions ()
1145
1182
config = DummyPConfig (options , 'notthere' , '/notthere' ,
0 commit comments