From 92c22f54f90320393b0d22648b317c614c9e4932 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Tue, 18 Nov 2014 09:05:32 +0100 Subject: [PATCH] Test message delete when claim expires The patch adds a test for message deletion after a claim has expired. The result of the test is that the message should be deleted. Unfortunately, some issues related to the state of the sqlalchemy driver make it quite hard for this test to work there without further changes. I'm proposing this patch with some skips in place for the scenarios where sqlalchemy is required, I'll propose a follow up patch to fix those issues and enable these tests. Closes-bug: #1369536 Change-Id: Icb12eed18c37455ad3528fa6a84fb8f2d8fcf19f --- .../unit/queues/storage/test_impl_mongodb.py | 10 +++++++ .../queues/storage/test_impl_sqlalchemy.py | 16 ++++++++++ zaqar/tests/queues/storage/base.py | 29 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/tests/unit/queues/storage/test_impl_mongodb.py b/tests/unit/queues/storage/test_impl_mongodb.py index f18ac677e..e0426f6d2 100644 --- a/tests/unit/queues/storage/test_impl_mongodb.py +++ b/tests/unit/queues/storage/test_impl_mongodb.py @@ -507,6 +507,16 @@ class PooledClaimsTests(base.ClaimControllerTest): control_driver_class = mongodb.ControlDriver controller_base_class = pooling.RoutingController + def test_delete_message_expired_claim(self): + # NOTE(flaper87): The pool tests uses sqlalchemy + # as one of the pools, which causes this test to fail. + # Several reasons to do this: + # The sqla driver is deprecated + # It's not optimized + # mocking utcnow mocks the driver too, which + # requires to put sleeps in the test + self.skip("Fix sqlalchemy driver") + @testing.requires_mongodb class MongodbFlavorsTest(base.FlavorsControllerTest): diff --git a/tests/unit/queues/storage/test_impl_sqlalchemy.py b/tests/unit/queues/storage/test_impl_sqlalchemy.py index ca8d8cd1d..b690ca8a1 100644 --- a/tests/unit/queues/storage/test_impl_sqlalchemy.py +++ b/tests/unit/queues/storage/test_impl_sqlalchemy.py @@ -115,6 +115,14 @@ class SqlalchemyClaimTests(base.ClaimControllerTest): driver_class = sqlalchemy.DataDriver controller_class = controllers.ClaimController + def test_delete_message_expired_claim(self): + # NOTE(flaper87): Several reasons to do this: + # The sqla driver is deprecated + # It's not optimized + # mocking utcnow mocks the driver too, which + # requires to put sleeps in the test + self.skip("Fix sqlalchemy driver") + class SqlalchemyPoolsTest(base.PoolsControllerTest): driver_class = sqlalchemy.ControlDriver @@ -155,6 +163,14 @@ class PooledClaimsTests(base.ClaimControllerTest): control_driver_class = sqlalchemy.ControlDriver controller_base_class = pooling.RoutingController + def test_delete_message_expired_claim(self): + # NOTE(flaper87): Several reasons to do this: + # The sqla driver is deprecated + # It's not optimized + # mocking utcnow mocks the driver too, which + # requires to put sleeps in the test + self.skip("Fix sqlalchemy driver") + class PooledQueueTests(base.QueueControllerTest): config_file = 'wsgi_sqlalchemy_pooled.conf' diff --git a/zaqar/tests/queues/storage/base.py b/zaqar/tests/queues/storage/base.py index a156e0c5b..84328e53f 100644 --- a/zaqar/tests/queues/storage/base.py +++ b/zaqar/tests/queues/storage/base.py @@ -19,6 +19,7 @@ import time import uuid import ddt +import mock from oslo.utils import timeutils import six from testtools import matchers @@ -881,6 +882,34 @@ class ClaimControllerTest(ControllerBaseTest): self.controller.update(self.queue_name, claim_id, meta, project=self.project) + def test_delete_message_expired_claim(self): + meta = {'ttl': 2, 'grace': 2} + new_messages = [{'ttl': 60, 'body': {}}, + {'ttl': 60, 'body': {}}, + {'ttl': 60, 'body': {}}] + + self.message_controller.post(self.queue_name, new_messages, + client_uuid=str(uuid.uuid1()), + project=self.project) + + claim_id, messages = self.controller.create(self.queue_name, meta, + project=self.project) + + now = timeutils.utcnow_ts() + timeutils_utcnow = 'oslo.utils.timeutils.utcnow_ts' + + with mock.patch(timeutils_utcnow) as mock_utcnow: + mock_utcnow.return_value = now + 2 + + messages = [msg['id'] for msg in messages] + self.message_controller.delete(self.queue_name, + messages.pop(), + project=self.project) + + self.message_controller.bulk_delete(self.queue_name, + messages, + project=self.project) + def test_illformed_id(self): # any ill-formed IDs should be regarded as non-existing ones.