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
This commit is contained in:
parent
5e9f60da85
commit
055a43777b
@ -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'),
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user