Exemple #1
0
def wait_for_registrations(client, number_of_registrations):
    with async_adapter.Timeout(TIMEOUT):
        while (
            len(client.session.registration_map.keys())
            < number_of_registrations
        ):
            async_adapter.sleep(0.01)
Exemple #2
0
def wait_for_messages(client, number_of_messages):
    messages_received = (client.session.message_handler.messages_received)

    with async_adapter.Timeout(TIMEOUT):
        while len(messages_received) < number_of_messages:
            async_adapter.sleep(0.01)

    return messages_received
Exemple #3
0
def assert_stops_raising(
        fn, exception_type=Exception, timeout=5, interval=0.1):

    with async_adapter.Timeout(timeout):
        while True:
            try:
                fn()
            except exception_type:
                pass
            else:
                return
            async_adapter.sleep(interval)
Exemple #4
0
    def _handshake(self, upgrade):
        handshake_headers = self._get_handshake_headers(upgrade=upgrade)
        handshake = '\r\n'.join(handshake_headers) + "\r\n\r\n"

        self.socket.send(handshake.encode())

        try:
            with async_adapter.Timeout(5):
                self.status, self.headers = self._read_handshake_response()
        except WampyTimeOut:
            raise WampyError(
                'No response after handshake "{}"'.format(handshake))

        logger.debug("connection upgraded")
Exemple #5
0
            def send_ping_and_expect_pong():
                payload = 'wampy::' + str(uuid.uuid4())
                # we send a Ping with a unique payload, and we expect
                # a Pong back echoing the same payload - but within the
                # deadline of ``heartbeat_timeout_seconds``.
                ping = Ping(payload=payload, mask_payload=True)

                try:
                    socket.sendall(bytes(ping.frame))
                except OSError:
                    # connection closed by parent thread, or wampy
                    # has been disconnected from server...
                    # either way, this gthread will be killed as
                    # soon if the Close message is received else
                    # schedule another Ping
                    logger.info('ping failed')
                    pass
                except BrokenPipeError:
                    logger.info('server ripped out from under us!')
                    pass

                pong = None

                with async_adapter.Timeout(heartbeat_timeout,
                                           raise_after=False):
                    while pong is None:
                        # required for Hub to implelent TimeOut
                        async_adapter.sleep()

                        try:
                            maybe_my_pong = self.pongs.get(block=False)
                        except async_adapter.QueueEmpty:
                            continue

                        if maybe_my_pong:
                            if maybe_my_pong.payload == payload:
                                pong = maybe_my_pong
                            else:
                                # possibly Pinging faster than the server is
                                # Ponging, else Hub hasn't scheduled the right
                                # gthread yet.
                                logger.error('Pongs out of order?')
                                self.pongs.put(maybe_my_pong)

                if pong is None:
                    logger.info('missed a Pong from the server')
                    self.missed_pongs += 1
Exemple #6
0
def wait_for_session(client):
    with async_adapter.Timeout(TIMEOUT):
        while client.session.id is None:
            async_adapter.sleep(0.01)