From dcfd379b176f5bcd3238d3e03cabfb3c81b259e4 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 12 Jan 2017 13:10:52 -0500 Subject: [PATCH] Queue cancelation test --- test/test_queue.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_queue.py b/test/test_queue.py index 44041779a..ca7012263 100644 --- a/test/test_queue.py +++ b/test/test_queue.py @@ -244,6 +244,31 @@ class TestQueue(QueueTestCase): count = self.queue.num_available_jobs_between(now, now, 'abc') self.assertEqual(0, count) + def test_cancel(self): + # Add an item. + self.queue.put(['somenamespace', 'abc', 'def'], self.TEST_MESSAGE_1, available_after=-10) + self.queue.put(['somenamespace', 'abc', 'def'], self.TEST_MESSAGE_2, available_after=-5) + + now = datetime.utcnow() + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/somenamespace']) + self.assertEqual(2, count) + + # Retrieve it. + item = self.queue.get() + self.assertIsNotNone(item) + + # Make sure we can cancel it. + self.assertTrue(self.queue.cancel(item.id)) + + now = datetime.utcnow() + count = self.queue.num_available_jobs_between(now - timedelta(seconds=60), now, + ['/somenamespace']) + self.assertEqual(1, count) + + # Make sure it is gone. + self.assertFalse(self.queue.cancel(item.id)) + def test_deleted_namespaced_items(self): self.queue = AutoUpdatingQueue(WorkQueue(QUEUE_NAME, self.transaction_factory, reporter=self.reporter,