Merge "Don't use claim creation time to calc claim's age"

This commit is contained in:
Jenkins 2013-08-14 15:53:17 +00:00 committed by Gerrit Code Review
commit e53c7ec194
2 changed files with 9 additions and 2 deletions

View File

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

View File

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