Esempio n. 1
0
    def test_item_is_stop_with_cascade_stop(self):
        """Return the name of the container that caused the cascade_stop"""
        queue = Queue()
        for item in QueueItem.stop('foobar-1'), QueueItem.new('a'), QueueItem.new('b'):
            queue.put(item)

        generator = consume_queue(queue, True)
        assert next(generator) is 'foobar-1'
Esempio n. 2
0
    def test_item_is_stop_without_cascade_stop(self):
        queue = Queue()
        for item in QueueItem.stop(), QueueItem.new('a'), QueueItem.new('b'):
            queue.put(item)

        generator = consume_queue(queue, False)
        assert next(generator) == 'a'
        assert next(generator) == 'b'
Esempio n. 3
0
    def test_item_is_an_exception(self):
        class Problem(Exception):
            pass

        queue = Queue()
        error = Problem("oops")
        for item in QueueItem.new("a"), QueueItem.new("b"), QueueItem.exception(error):
            queue.put(item)

        generator = consume_queue(queue, False)
        assert next(generator) == "a"
        assert next(generator) == "b"
        with pytest.raises(Problem):
            next(generator)
Esempio n. 4
0
 def test_item_is_none_when_timeout_is_hit(self):
     queue = Queue()
     generator = consume_queue(queue, False)
     assert next(generator) is None
Esempio n. 5
0
    def test_item_is_stop_with_cascade_stop(self):
        queue = Queue()
        for item in QueueItem.stop(), QueueItem.new('a'), QueueItem.new('b'):
            queue.put(item)

        assert list(consume_queue(queue, True)) == []