Пример #1
0
async def test_stream_cancel_by_ping():
    ctx = ClientServer(PingServiceHandler, PingServiceStub,
                       config=Configuration(_keepalive_time=0.01,
                                            _keepalive_timeout=0.04,
                                            _http2_max_pings_without_data=1,
                                            ))

    # should be successful
    async with ctx as (handler, stub):
        await stub.UnaryStream(DummyRequest(value='ping'))
        assert ctx.channel._protocol.connection.last_ping_sent is not None

    # disable ping ack logic to cause a timeout and disconnect
    with patch.object(Connection, 'ping_ack_process') as p:
        p.return_value = None
        with pytest.raises(StreamTerminatedError, match='Connection lost'):
            async with ctx as (handler, stub):
                await stub.UnaryStream(DummyRequest(value='ping'))
Пример #2
0
    def __init__(self):
        server_h2_config = H2Configuration(
            client_side=False,
            header_encoding='ascii',
        )
        self.server_h2c = H2Connection(server_h2_config)

        self.to_server_transport = TransportStub(self.server_h2c)

        client_h2_config = H2Configuration(
            client_side=True,
            header_encoding='ascii',
        )
        self.client_proto = H2Protocol(
            client.Handler(),
            Configuration().__for_test__(),
            client_h2_config,
        )
        self.client_proto.connection_made(self.to_server_transport)
Пример #3
0
    def __init__(self):
        client_h2_config = H2Configuration(
            client_side=True,
            header_encoding='ascii',
        )
        self.client_h2c = H2Connection(client_h2_config)

        self.to_client_transport = TransportStub(self.client_h2c)
        self.client_h2c.initiate_connection()

        server_config = H2Configuration(
            client_side=False,
            header_encoding='ascii',
        )
        self.server_proto = H2Protocol(
            DummyHandler(),
            Configuration().__for_test__(),
            server_config,
        )
        self.server_proto.connection_made(self.to_client_transport)

        # complete settings exchange and clear events buffer
        self.client_flush()
        self.to_client_transport.events()
Пример #4
0
def test_configuration():
    # all params should be optional
    config = Configuration()
    _with_defaults(config, 'client-default')
    _with_defaults(config, 'server-default')
Пример #5
0
@pytest.mark.parametrize('cert', [None, object()])
def test_peer_cert(cert):
    ssl_object = Mock()
    ssl_object.getpeercert.return_value = cert

    transport = Mock()
    transport.get_extra_info.return_value = ssl_object

    peer = Peer(transport)
    assert peer.cert() is cert
    transport.get_extra_info.assert_called_once_with('ssl_object')
    ssl_object.getpeercert.assert_called_once_with()


@pytest.mark.parametrize('config', [
    Configuration(http2_connection_window_size=2**16 - 1),
    Configuration(http2_connection_window_size=2**31 - 1),
    Configuration(http2_stream_window_size=2**16 - 1),
    Configuration(http2_stream_window_size=2**31 - 1),
])
def test_max_window_size(config):
    server_h2c = H2Connection(
        H2Configuration(client_side=False, header_encoding='ascii'))
    proto = H2Protocol(Mock(), config.__for_test__(),
                       H2Configuration(client_side=True))
    proto.connection_made(TransportStub(server_h2c))
    assert server_h2c.outbound_flow_control_window \
        == config.http2_connection_window_size
    assert server_h2c.remote_settings.initial_window_size \
        == config.http2_stream_window_size
Пример #6
0
def config_fixture():
    return Configuration().__for_test__()