diff --git a/marconi/storage/mongodb/messages.py b/marconi/storage/mongodb/messages.py index 48d52c1bf..df943dead 100644 --- a/marconi/storage/mongodb/messages.py +++ b/marconi/storage/mongodb/messages.py @@ -373,8 +373,11 @@ class MessageController(storage.MessageBase): except ValueError: return + # NOTE(cpp-cabrera): unclaim by setting the claim ID to None + # and the claim expiration time to now + now = timeutils.utcnow() self._col.update({'q': queue_name, 'p': project, 'c.id': cid}, - {'$set': {'c': {'id': None, 'e': 0}}}, + {'$set': {'c': {'id': None, 'e': now}}}, upsert=False, multi=True) def remove_expired(self): diff --git a/marconi/tests/transport/wsgi/test_messages.py b/marconi/tests/transport/wsgi/test_messages.py index 2d93f7489..3ac9f253e 100644 --- a/marconi/tests/transport/wsgi/test_messages.py +++ b/marconi/tests/transport/wsgi/test_messages.py @@ -311,6 +311,27 @@ class MessagesBaseTest(base.TestBase): self.simulate_get(path, '7e7e7e') self.assertEquals(self.srmock.status, falcon.HTTP_400) + # NOTE(cpp-cabrera): regression test against bug #1210633 + def test_when_claim_deleted_then_messages_unclaimed(self): + path = self.queue_path + self._post_messages(path + '/messages', repeat=5) + + # post claim + self.simulate_post(path + '/claims', self.project_id, + body='{"ttl": 100, "grace": 100}') + self.assertEquals(self.srmock.status, falcon.HTTP_201) + location = self.srmock.headers_dict['Location'] + + # release claim + self.simulate_delete(location, self.project_id) + self.assertEquals(self.srmock.status, falcon.HTTP_204) + + # get unclaimed messages + self.simulate_get(path + '/messages', self.project_id, + query_string='echo=true', + headers=self.headers) + self.assertEquals(self.srmock.status, falcon.HTTP_200) + def _post_messages(self, target, repeat=1): doc = json.dumps([{'body': 239, 'ttl': 300}] * repeat) self.simulate_post(target, self.project_id, body=doc,