fix(mongo): Negative age reported in stats
This patch includes a one-line fix, along with a regression test to verify the same. Change-Id: Iffb3cb7c243296b1caacc95e1edd3c6f63c34a4b Closes-Bug: #1237620
This commit is contained in:
parent
2273b2f587
commit
33f75cd592
@ -128,7 +128,7 @@ def stat_message(message, now):
|
||||
"""Creates a stat document from the given message, relative to now."""
|
||||
oid = message['_id']
|
||||
created = oid_ts(oid)
|
||||
age = created - now
|
||||
age = now - created
|
||||
|
||||
return {
|
||||
'id': str(oid),
|
||||
|
@ -132,7 +132,7 @@ class QueueControllerTest(ControllerBaseTest):
|
||||
# NOTE(kgriffs): We can't get around doing this, because
|
||||
# we don't know how the storage drive may be calculating
|
||||
# message timestamps (and may not be monkey-patchable).
|
||||
time.sleep(1)
|
||||
time.sleep(1.2)
|
||||
|
||||
_insert_fixtures(self.message_controller, 'test',
|
||||
project=self.project, client_uuid=client_uuid,
|
||||
@ -150,6 +150,9 @@ class QueueControllerTest(ControllerBaseTest):
|
||||
|
||||
self.assertNotEqual(oldest, newest)
|
||||
|
||||
age = oldest['age']
|
||||
self.assertThat(age, matchers.GreaterThan(0))
|
||||
|
||||
# NOTE(kgriffs): Ensure is different enough
|
||||
# for the next comparison to work.
|
||||
soon = timeutils.utcnow() + datetime.timedelta(seconds=60)
|
||||
|
Loading…
x
Reference in New Issue
Block a user