diff --git a/test/test_queue.py b/test/test_queue.py index 8626325aa..44041779a 100644 --- a/test/test_queue.py +++ b/test/test_queue.py @@ -244,5 +244,49 @@ class TestQueue(QueueTestCase): count = self.queue.num_available_jobs_between(now, now, 'abc') self.assertEqual(0, count) + def test_deleted_namespaced_items(self): + self.queue = AutoUpdatingQueue(WorkQueue(QUEUE_NAME, self.transaction_factory, + reporter=self.reporter, + has_namespace=True)) + + self.queue.put(['somenamespace', 'abc', 'def'], self.TEST_MESSAGE_1, available_after=-10) + self.queue.put(['somenamespace', 'abc', 'ghi'], self.TEST_MESSAGE_2, available_after=-5) + self.queue.put(['anothernamespace', 'abc', 'def'], self.TEST_MESSAGE_1, available_after=-10) + + # Ensure we have 2 items under `somenamespace` and 1 item under `anothernamespace`. + now = datetime.utcnow() + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/somenamespace']) + self.assertEqual(2, count) + + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/anothernamespace']) + self.assertEqual(1, count) + + # Delete all `somenamespace` items. + self.queue.delete_namespaced_items('somenamespace') + + # Check the updated counts. + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/somenamespace']) + self.assertEqual(0, count) + + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/anothernamespace']) + self.assertEqual(1, count) + + # Delete all `anothernamespace` items. + self.queue.delete_namespaced_items('anothernamespace') + + # Check the updated counts. + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/somenamespace']) + self.assertEqual(0, count) + + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/anothernamespace']) + self.assertEqual(0, count) + + if __name__ == '__main__': unittest.main()