def test_check_timeouts_no_timeout(protocol: HttpProtocol): protocol.keep_alive_timeout = 1 protocol.loop.call_later = Mock() protocol.check_timeouts() protocol._task.cancel.assert_not_called() assert protocol._http.stage is Stage.IDLE assert protocol._http.exception is None protocol.loop.call_later.assert_called_with( protocol.keep_alive_timeout / 2, protocol.check_timeouts)
async def test_request_stream_unread(app): """ensure no error is raised when leaving unread bytes in byte-buffer""" err = None protocol = HttpProtocol(loop=asyncio.get_event_loop(), app=app) try: protocol.request = None protocol._body_chunks.append("this is a test") await protocol.stream_append() except AttributeError as e: err = e assert err is None and not protocol._body_chunks
def protocol(app, mock_transport): loop = asyncio.new_event_loop() protocol = HttpProtocol(loop=loop, app=app) protocol.connection_made(mock_transport) protocol._setup_connection() protocol._task = Mock(spec=asyncio.Task) protocol._task.cancel = Mock() return protocol
def test_check_timeouts_response_timeout(protocol: HttpProtocol): protocol._http.stage = Stage.RESPONSE protocol._time = 0 protocol.check_timeouts() protocol._task.cancel.assert_called_once() assert isinstance(protocol._http.exception, ServiceUnavailable)
def test_check_timeouts_request_timeout(protocol: HttpProtocol): protocol._http.stage = Stage.REQUEST protocol._time = 0 protocol.check_timeouts() protocol._task.cancel.assert_called_once() assert isinstance(protocol._http.exception, RequestTimeout)
def test_check_timeouts_keep_alive_timeout(protocol: HttpProtocol): protocol._http.stage = Stage.IDLE protocol._time = 0 protocol.check_timeouts() protocol._task.cancel.assert_called_once() assert protocol._http.exception is None