diff --git a/marconi/storage/mongodb/claims.py b/marconi/storage/mongodb/claims.py index 8e58e2c6b..ec7e98f1e 100644 --- a/marconi/storage/mongodb/claims.py +++ b/marconi/storage/mongodb/claims.py @@ -72,8 +72,6 @@ class ClaimController(storage.ClaimBase): except ValueError: raise exceptions.ClaimDoesNotExist() - age = timeutils.delta_seconds(utils.oid_utc(cid), now) - def messages(msg_iter): msg = next(msg_iter) yield msg.pop('claim') @@ -91,6 +89,10 @@ class ClaimController(storage.ClaimBase): msgs = messages(msg_ctrl.claimed(queue, cid, now, project=project)) claim = next(msgs) + + update_time = claim['e'] - datetime.timedelta(seconds=claim['t']) + age = timeutils.delta_seconds(update_time, now) + claim = { 'age': int(age), 'ttl': claim.pop('t'), diff --git a/marconi/tests/transport/wsgi/test_claims.py b/marconi/tests/transport/wsgi/test_claims.py index 837d7a428..5f7848c0d 100644 --- a/marconi/tests/transport/wsgi/test_claims.py +++ b/marconi/tests/transport/wsgi/test_claims.py @@ -21,6 +21,7 @@ import pymongo import falcon from marconi.common import config +from marconi.openstack.common import timeutils from marconi.tests.transport.wsgi import base @@ -154,15 +155,19 @@ class ClaimsBaseTest(base.TestBase): # Update the claim new_claim_ttl = '{"ttl": 60}' + creation = timeutils.utcnow() self.simulate_patch(claim_href, self.project_id, body=new_claim_ttl) self.assertEquals(self.srmock.status, falcon.HTTP_204) # Get the claimed messages (again) body = self.simulate_get(claim_href, self.project_id) + query = timeutils.utcnow() claim = json.loads(body[0]) message_href, params = claim['messages'][0]['href'].split('?') self.assertEquals(claim['ttl'], 60) + estimated_age = timeutils.delta_seconds(creation, query) + self.assertTrue(estimated_age > claim['age']) # Delete the claim self.simulate_delete(claim['href'], 'bad_id')