示例#1
0
def test_receive_client_disconnected(make_request, loop, reader):
    req = make_request('GET', '/')
    ws = WebSocketResponse()
    yield from ws.prepare(req)

    exc = errors.ClientDisconnectedError()
    res = helpers.create_future(loop)
    res.set_exception(exc)
    reader.read = make_mocked_coro(res)

    msg = yield from ws.receive()
    assert ws.closed
    assert msg.tp == WSMsgType.close
    assert msg.data is None
    assert ws.exception() is None
示例#2
0
    def test_receive_client_disconnected(self):
        req = self.make_request('GET', '/')
        ws = WebSocketResponse()
        ws.start(req)

        exc = errors.ClientDisconnectedError()
        res = asyncio.Future(loop=self.loop)
        res.set_exception(exc)
        ws._reader.read.return_value = res

        @asyncio.coroutine
        def go():
            msg = yield from ws.receive()
            self.assertTrue(ws.closed)
            self.assertTrue(msg.tp, MsgType.close)
            self.assertIs(msg.data, None)
            self.assertIs(ws.exception(), None)

        self.loop.run_until_complete(go())
示例#3
0
def test_raw_server_do_not_swallow_exceptions(raw_test_server, test_client):
    exc = None

    @asyncio.coroutine
    def handler(request):
        raise exc

    logger = mock.Mock()
    server = yield from raw_test_server(handler, logger=logger)
    client = yield from test_client(server)

    for _exc, msg in ((asyncio.CancelledError("error"),
                       'Request handler cancelled.'),
                      (errors.ClientDisconnectedError("error"),
                       'Ignored premature client disconnection #1.')):
        exc = _exc
        with pytest.raises(errors.ClientResponseError):
            yield from client.get('/path/to')

        logger.debug.assert_called_with(msg)