test(queue): delete_namespaced_items

Add queue tests for delete_namespaced_items
This commit is contained in:
Joseph Schorr 2017-01-09 11:05:39 -05:00
parent e658941a43
commit ce21788da8

View file

@ -244,5 +244,49 @@ 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_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__': if __name__ == '__main__':
unittest.main() unittest.main()