Пример #1
0
 def test_receive_handshake(self):
     message = Message(channel=ChannelId.META_HANDSHAKE)
     assert self.extension.receive(message) == message
     assert not self.extension.server_supports_acks
     message.ext = {AckExtension.FIELD_ACK: True}
     assert self.extension.receive(message) == message
     assert self.extension.server_supports_acks
Пример #2
0
 def test_receive_handshake(self):
     message = Message(channel=ChannelId.META_HANDSHAKE)
     assert self.extension.receive(message) is message
     assert not self.extension.server_supports_acks
     message.ext = {AckExtension.FIELD_ACK: True}
     assert self.extension.receive(message) is message
     assert self.extension.server_supports_acks
Пример #3
0
    def test_receive_connect(self):

        # Check that nothing happens when no ACK ID is included
        message = Message(channel=ChannelId.META_CONNECT, successful=True)
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is None
        assert not self.extension.server_supports_acks

        # Check that nothing happens when server support is unknown
        message.ext = {AckExtension.FIELD_ACK: 1}
        assert self.extension.receive(message) == message
        assert self.extension.ack_id is None
        assert not self.extension.server_supports_acks

        # Notify the extension that server supports ACKs
        self.extension.receive(Message(
            channel=ChannelId.META_HANDSHAKE,
            ext={AckExtension.FIELD_ACK: True}
        ))

        # Check that the ACK ID is captured
        assert self.extension.server_supports_acks
        assert self.extension.receive(message) == message
        assert self.extension.ack_id == 1

        # Check that the ACK ID is ignored for failed messages
        message.ext[AckExtension.FIELD_ACK] = 2
        message.successful = False
        assert self.extension.receive(message) == message
        assert self.extension.ack_id == 1

        # Check that the ACK ID is ignored if not an integer
        message.ext[AckExtension.FIELD_ACK] = '2'
        message.successful = True
        assert self.extension.receive(message) == message
        assert self.extension.ack_id == 1

        # Check that updates to the ACK ID are captured
        message.ext[AckExtension.FIELD_ACK] = 2
        assert self.extension.receive(message) == message
        assert self.extension.ack_id == 2
Пример #4
0
    def test_receive_connect(self):

        # Check that nothing happens when no ACK ID is included
        message = Message(channel=ChannelId.META_CONNECT, successful=True)
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is None
        assert not self.extension.server_supports_acks

        # Check that nothing happens when server support is unknown
        message.ext = {AckExtension.FIELD_ACK: 1}
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is None
        assert not self.extension.server_supports_acks

        # Notify the extension that server supports ACKs
        self.extension.receive(Message(
            channel=ChannelId.META_HANDSHAKE,
            ext={AckExtension.FIELD_ACK: True}
        ))

        # Check that the ACK ID is captured
        assert self.extension.server_supports_acks
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is 1

        # Check that the ACK ID is ignored for failed messages
        message.ext[AckExtension.FIELD_ACK] = 2
        message.successful = False
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is 1

        # Check that the ACK ID is ignored if not an integer
        message.ext[AckExtension.FIELD_ACK] = '2'
        message.successful = True
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is 1

        # Check that updates to the ACK ID are captured
        message.ext[AckExtension.FIELD_ACK] = 2
        assert self.extension.receive(message) is message
        assert self.extension.ack_id is 2