async def test_on_queue_message_bulk_size_bigger_that_one(self):
        """
        Confere que o handler real só é chamado quando o bucket atinge o limite máximo de
        tamanho. E que o handler é chamado com a lista de mensagens.
        * Bucket deve estart vazio após o "flush"
        """

        class MyBucket(Bucket):
            def pop_all(self):
                return self._items

        handler_mock = CoroutineMock()
        self.one_route_fixture["handler"] = handler_mock
        self.one_route_fixture["options"]["bulk_size"] = 2

        consumer = SSEConsumer(
            self.one_route_fixture, *(self.consumer_params + (MyBucket,))
        )

        result = await consumer.on_event(
            b"deployment_info", b'{"key": "value"}'
        )
        self.assertEqual(0, handler_mock.await_count)

        result = await consumer.on_event(
            b"deployment_info", b'{"key": "value"}'
        )
        handler_mock.assert_awaited_once_with(consumer.bucket._items)
示例#2
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")
示例#3
0
    async def test_it_waits_before_trying_to_reconnect_if_connect_fails(self):

        coro = CoroutineMock()
        with asynctest.patch(
            "asyncworker.easyqueue.queue.asyncio.sleep"
        ) as sleep, asynctest.patch.object(
            self.queue.connection,
            "_connect",
            CoroutineMock(side_effect=[ConnectionError, True]),
        ):
            wrapped = _ensure_conn_is_ready(ConnType.CONSUME)(coro)
            await wrapped(self.queue, 1, dog="Xablau")
            sleep.assert_awaited_once_with(self.seconds)

            # todo: CoroutineMock.side_effect is raised only on call, not on await
            self.queue.connection._connect.assert_has_awaits([call()])
            self.queue.connection._connect.assert_has_calls([call(), call()])
            coro.assert_awaited_once_with(self.queue, 1, dog="Xablau")
示例#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")
示例#5
0
    async def test_call_syntaxes(self):
        _set_limits = CoroutineMock()
        _show_limits = CoroutineMock()
        self.patch(RateLimitCmd,
                   _set_limits=_set_limits,
                   _show_limits=_show_limits)

        await self.execute(RateLimitCmd, 'up', '1Mb', 'limit-rate-up<1k')
        _set_limits.assert_awaited_once_with(['limit-rate-up<1k'], ('up', ),
                                             '1Mb',
                                             adjust=False,
                                             quiet=False)
        _show_limits.assert_not_awaited()
        _set_limits.reset_mock()
        _show_limits.reset_mock()  # noqa: E702

        await self.execute(RateLimitCmd, 'up', '1Mb')
        _set_limits.assert_awaited_once_with([], ('up', ),
                                             '1Mb',
                                             adjust=False,
                                             quiet=False)
        _show_limits.assert_not_awaited()
        _set_limits.reset_mock()
        _show_limits.reset_mock()  # noqa: E702

        await self.execute(RateLimitCmd, 'up')
        _set_limits.assert_not_awaited()
        _show_limits.assert_awaited_once_with([], ('up', ))
        _set_limits.reset_mock()
        _show_limits.reset_mock()  # noqa: E702

        await self.execute(RateLimitCmd, 'up', 'show', 'limit-rate-up<1k')
        _set_limits.assert_not_awaited()
        _show_limits.assert_awaited_once_with(['limit-rate-up<1k'], ('up', ))
        _set_limits.reset_mock()
        _show_limits.reset_mock()  # noqa: E702