From 055a43777b2f4d5bb78f1a9fea6f952ffb3087c7 Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Wed, 14 Aug 2013 16:39:50 +0200 Subject: [PATCH] Don't use claim creation time to calc claim's age Mongodb's driver uses Claim's creation time to estimate claims age instead, it should use claim's update time. Since there's no update / creation time in mongodb's claims, the patch estimates claims age by doing: delta(expiration - ttl, now) This change fixes the issue bellow and makes mongodb's claims compliant with Marconi's specs. Change-Id: I72c968236ecd239e7b885b293238e2920807a57c Closes-Bug: #1210662 --- marconi/storage/mongodb/claims.py | 6 ++++-- marconi/tests/transport/wsgi/test_claims.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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')