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:
kgriffs 2013-10-09 20:32:59 -04:00
parent 2273b2f587
commit 33f75cd592
2 changed files with 5 additions and 2 deletions

View File

@ -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),

View File

@ -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)