示例#1
0
    async def test_it_doesnt_calls_connect_if_queue_is_connected(self):
        async_queue = Mock(
            connection=Mock(is_connected=True, _connect=CoroutineMock()))
        coro = CoroutineMock()
        wrapped = _ensure_connected(coro)
        await wrapped(async_queue, 1, dog="Xablau")

        async_queue.connection._connect.assert_not_awaited()
        coro.assert_awaited_once_with(async_queue, 1, dog="Xablau")
示例#2
0
    async def test_it_logs_connection_retries_if_a_logger_istance_is_available(
            self):
        async_queue = Mock(
            is_running=True,
            connection=Mock(
                _connect=CoroutineMock(side_effect=[ConnectionError, True]),
                is_connected=False,
            ),
            logger=Mock(spec=logging.Logger),
        )
        coro = CoroutineMock()
        with asynctest.patch(
                "asyncworker.easyqueue.queue.asyncio.sleep") as sleep:
            wrapped = _ensure_connected(coro)
            await wrapped(async_queue, 1, dog="Xablau")

        async_queue.logger.error.assert_called_once()
示例#3
0
    async def test_it_calls_connection_fail_callback_if_connect_fails(self):
        error = ConnectionError()
        async_queue = Mock(
            is_running=True,
            connection=Mock(
                _connect=CoroutineMock(side_effect=[error, True]),
                is_connected=False,
            ),
            connection_fail_callback=CoroutineMock(),
        )
        coro = CoroutineMock()
        with asynctest.patch(
            "asyncworker.easyqueue.queue.asyncio.sleep"
        ) as sleep:
            wrapped = _ensure_connected(coro)
            await wrapped(async_queue, 1, dog="Xablau")

        async_queue.connection_fail_callback.assert_awaited_once_with(error, 1)
示例#4
0
    async def test_it_waits_before_trying_to_reconnect_if_connect_fails(self):
        seconds = 666
        async_queue = Mock(
            is_running=True,
            connection=Mock(
                is_connected=False,
                _connect=CoroutineMock(side_effect=[ConnectionError, True]),
            ),
            seconds_between_conn_retry=seconds,
        )
        coro = CoroutineMock()
        with asynctest.patch(
                "asyncworker.easyqueue.queue.asyncio.sleep") as sleep:
            wrapped = _ensure_connected(coro)
            await wrapped(async_queue, 1, dog="Xablau")
            sleep.assert_awaited_once_with(seconds)

        # todo: CoroutineMock.side_effect is raised only on call, not on await
        async_queue.connection._connect.assert_has_awaits([call()])
        async_queue.connection._connect.assert_has_calls([call(), call()])
        coro.assert_awaited_once_with(async_queue, 1, dog="Xablau")