Skip to content

Commit

Permalink
Don't report negative uptime for a process if system time changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaberez authored and idanarye committed Nov 23, 2015
1 parent 62dd947 commit d46e346
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions supervisor/rpcinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ def _interpretProcessInfo(self, info):
start_dt = datetime.datetime(*time.gmtime(start)[:6])
now_dt = datetime.datetime(*time.gmtime(now)[:6])
uptime = now_dt - start_dt
if uptime.total_seconds() < 0: # system time set back
uptime = datetime.timedelta(0)
desc = 'pid %s, uptime %s' % (info['pid'], uptime)

elif state in (ProcessStates.FATAL, ProcessStates.BACKOFF):
Expand Down
12 changes: 12 additions & 0 deletions supervisor/tests/test_rpcinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,18 @@ def test__interpretProcessInfo(self):
description = interface._interpretProcessInfo(stopped2)
self.assertEqual(description, 'Not started')

def test__interpretProcessInfo_doesnt_report_negative_uptime(self):
supervisord = DummySupervisor()
interface = self._makeOne(supervisord)
from supervisor.process import ProcessStates
running = {'name': 'running',
'pid': 42,
'state': ProcessStates.RUNNING,
'start': _NOW + 10, # started in the future
'stop': None,
'now': _NOW}
description = interface._interpretProcessInfo(running)
self.assertEqual(description, 'pid 42, uptime 0:00:00')

def test_getProcessInfo(self):
from supervisor.process import ProcessStates
Expand Down

0 comments on commit d46e346

Please sign in to comment.