Skip to content

Commit 8171a22

Browse files
author
Joe LeVeque
committed
Add test for case where process entered RUNNING state but then clock rolled back to be less than startsecs
1 parent 75e9804 commit 8171a22

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

supervisor/tests/test_process.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,43 @@ def test_finish_starting_state_exited_too_quickly(self):
11401140
self.assertEqual(event.__class__, events.ProcessStateBackoffEvent)
11411141
self.assertEqual(event.from_state, ProcessStates.STARTING)
11421142

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+
11431180
def test_finish_running_state_laststart_in_future(self):
11441181
options = DummyOptions()
11451182
config = DummyPConfig(options, 'notthere', '/notthere',

0 commit comments

Comments
 (0)