Queue cancelation test

This commit is contained in:
Joseph Schorr 2017-01-12 13:10:52 -05:00
parent 8ca8c17e27
commit dcfd379b17

View file

@ -244,6 +244,31 @@ class TestQueue(QueueTestCase):
count = self.queue.num_available_jobs_between(now, now, 'abc') count = self.queue.num_available_jobs_between(now, now, 'abc')
self.assertEqual(0, count) 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): def test_deleted_namespaced_items(self):
self.queue = AutoUpdatingQueue(WorkQueue(QUEUE_NAME, self.transaction_factory, self.queue = AutoUpdatingQueue(WorkQueue(QUEUE_NAME, self.transaction_factory,
reporter=self.reporter, reporter=self.reporter,