Example #1
0
    def _follow_advice(self, reconnect_advice: str,
                       reconnect_timeout: Union[int, float, None]) -> None:
        """Follow the server's reconnect advice

        Either a :obj:`_connect` or :obj:`handshake` operation is started
        based on the *reconnect_advice* or the method returns without starting
        any operation if a different advice is specified.

        :param reconnect_advice: Reconnect advice parameter that determines \
        which operation should be started.
        :param reconnect_timeout: Initial connection delay to pass to \
        :obj:`_connect` or :obj:`handshake`.
        """
        # do a handshake operation if advised
        if reconnect_advice == "handshake":
            handshake_coro = defer(self.handshake,
                                   delay=reconnect_timeout,
                                   loop=self._loop)
            self._start_connect_task(handshake_coro([self.connection_type]))

        # do a connect operation if advised
        elif reconnect_advice == "retry":
            connect_coro = defer(self._connect,
                                 delay=reconnect_timeout,
                                 loop=self._loop)
            self._start_connect_task(connect_coro())

        # there is not reconnect advice from the server or its value
        # is none
        else:
            LOGGER.warning("No reconnect advice provided, no more operations "
                           "will be scheduled.")
            self._state = TransportState.SERVER_DISCONNECTED
Example #2
0
    async def test_defer_none_delay(self, sleep):
        argument = object()
        wrapper = defer(self.coro_func)

        result = await wrapper(argument)

        self.assertIs(result, argument)
        sleep.assert_not_called()
Example #3
0
    async def test_defer_no_loop(self, sleep):
        argument = object()
        delay = 10
        wrapper = defer(self.coro_func, delay)

        result = await wrapper(argument)

        self.assertIs(result, argument)
        sleep.assert_called_with(delay, loop=None)
Example #4
0
    async def test_defer_sleep_canceled(self, sleep):
        argument = object()
        delay = 10
        wrapper = defer(self.coro_func, delay)
        sleep.side_effect = asyncio.CancelledError()

        with self.assertRaises(asyncio.CancelledError):
            await wrapper(argument)

        sleep.assert_called_with(delay, loop=None)