Skip to content

Commit

Permalink
Merge "Don't use claim creation time to calc claim's age"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 14, 2013
2 parents fff83ba + 055a437 commit e53c7ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions marconi/storage/mongodb/claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def get(self, queue, claim_id, project=None):
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')
Expand All @@ -91,6 +89,10 @@ def messages(msg_iter):
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'),
Expand Down
5 changes: 5 additions & 0 deletions marconi/tests/transport/wsgi/test_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import falcon

from marconi.common import config
from marconi.openstack.common import timeutils
from marconi.tests.transport.wsgi import base


Expand Down Expand Up @@ -154,15 +155,19 @@ def test_lifecycle(self):

# 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')
Expand Down

0 comments on commit e53c7ec

Please sign in to comment.