From 31d6bb6d94a1a2921bdadd507d375f1ba2c20f83 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Tue, 28 Jun 2016 22:32:21 +0200 Subject: [PATCH] Fix issue with subscription list in Redis In the Redis storage driver, we don't manage the marker of subscription list properly, returning the same item as the marker when we are at the list limit. This manages it properly by fixing how we handle the rank calculated. Change-Id: Ifedd970c467a8e9e2f59123240f3844d884984c9 --- zaqar/storage/redis/subscriptions.py | 2 +- zaqar/tests/unit/storage/base.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/zaqar/storage/redis/subscriptions.py b/zaqar/storage/redis/subscriptions.py index 4564a3bdb..700ed6e24 100644 --- a/zaqar/storage/redis/subscriptions.py +++ b/zaqar/storage/redis/subscriptions.py @@ -60,7 +60,7 @@ class SubscriptionController(base.Subscription): project, SUBSCRIPTION_IDS_SUFFIX) rank = client.zrank(subset_key, marker) - start = rank + 1 if rank else 0 + start = rank + 1 if rank is not None else 0 cursor = (q for q in client.zrange(subset_key, start, start + limit - 1)) diff --git a/zaqar/tests/unit/storage/base.py b/zaqar/tests/unit/storage/base.py index d0ec7013f..6fa15ec64 100644 --- a/zaqar/tests/unit/storage/base.py +++ b/zaqar/tests/unit/storage/base.py @@ -1053,6 +1053,31 @@ class SubscriptionControllerTest(ControllerBaseTest): subscriptions))) self.assertEqual(5, len(subscriptions)) + def test_small_list(self): + subscriber = 'http://fake' + s_id = self.subscription_controller.create( + self.source, + subscriber, + self.ttl, + self.options, + project=self.project) + self.addCleanup(self.subscription_controller.delete, self.source, + s_id, self.project) + + interaction = self.subscription_controller.list(self.source, + project=self.project) + subscriptions = list(next(interaction)) + marker = next(interaction) + + self.assertEqual(1, len(subscriptions)) + + interaction = (self.subscription_controller.list(self.source, + project=self.project, + marker=marker)) + subscriptions = list(next(interaction)) + + self.assertEqual([], subscriptions) + @ddt.data(True, False) def test_get_raises_if_subscription_does_not_exist(self, precreate_queue): self._precreate_queue(precreate_queue)