How to use the janus.LifoQueue function in janus

To help you get started, we’ve selected a few janus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / janus / tests / test_sync.py View on Github external
    @pytest.mark.asyncio
    async def test_maxsize(self):
        # Test to make sure a queue task completed successfully.
        _q = self.type2test(5)
        q = _q.sync_q
        self.assertEqual(q.maxsize, 5)
        _q.close()
        await _q.wait_closed()


class QueueTest(BaseQueueTestMixin, unittest.TestCase):
    type2test = janus.Queue


class LifoQueueTest(BaseQueueTestMixin, unittest.TestCase):
    type2test = janus.LifoQueue


class PriorityQueueTest(BaseQueueTestMixin, unittest.TestCase):
    type2test = janus.PriorityQueue


# A Queue subclass that can provoke failure at a moment's notice :)
class FailingQueueException(Exception):
    pass


class FailingQueue(janus.Queue):
    def __init__(self, *args, **kwargs):
        self.fail_next_put = False
        self.fail_next_get = False
        super().__init__(*args, **kwargs)
github aio-libs / janus / tests / test_async.py View on Github external
async def test_order(self):
        _q = janus.LifoQueue()
        q = _q.async_q
        for i in [1, 3, 2]:
            q.put_nowait(i)

        items = [q.get_nowait() for _ in range(3)]
        self.assertEqual([2, 3, 1], items)

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed()
github aio-libs / janus / tests / test_async.py View on Github external
self.assertEqual(q._format(), 'maxsize=0')

        q._unfinished_tasks = 2
        self.assertEqual(q._format(), 'maxsize=0 tasks=2')

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed()


class QueueJoinTests(_QueueJoinTestMixin, unittest.TestCase):
    q_class = janus.Queue


class LifoQueueJoinTests(_QueueJoinTestMixin, unittest.TestCase):
    q_class = janus.LifoQueue


class PriorityQueueJoinTests(_QueueJoinTestMixin, unittest.TestCase):
    q_class = janus.PriorityQueue