python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.23k stars 519 forks source link

执行pytest失败,报TimeoutError #1510

Closed dabao1990 closed 2 months ago

dabao1990 commented 2 months ago

NAME="openEuler" VERSION="20.03 (LTS)"

====================== spack install websockets@13.1 cd websockets/tests

======================= 执行pytest,报如下错误

=======================

self =

async def test_keepalive_is_enabled(self):
    """Client enables keepalive and measures latency by default."""
    async with serve(*args) as server:
        async with connect(get_uri(server), ping_interval=MS) as client:
            self.assertEqual(client.latency, 0)
            await asyncio.sleep(2 * MS)
          self.assertGreater(client.latency, 0)

E AssertionError: 0 not greater than 0

asyncio/testclient.py:119: AssertionError ____ ClientConnectionTests.test_close_waits_for_close_frame __

self =

async def test_close_waits_for_close_frame(self):
    """close waits for a close frame (then EOF) before returning."""
    async with self.delay_frames_rcvd(MS), self.delay_eof_rcvd(MS):
        await self.connection.close()

    with self.assertRaises(ConnectionClosedOK) as raised:
        await self.connection.recv()

    exc = raised.exception
    self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
  self.assertIsNone(exc.__cause__)

E AssertionError: TimeoutError('timed out while closing connection') is not None

asyncio/test_connection.py:663: AssertionError __ ClientConnectionTests.test_close_waits_for_connection_closed ___

self =

async def test_close_waits_for_connection_closed(self):
    """close waits for EOF before returning."""
    if self.LOCAL is SERVER:
        self.skipTest("only relevant on the client-side")

    async with self.delay_eof_rcvd(MS):
        await self.connection.close()

    with self.assertRaises(ConnectionClosedOK) as raised:
        await self.connection.recv()

    exc = raised.exception
    self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
  self.assertIsNone(exc.__cause__)

E AssertionError: TimeoutError('timed out while closing connection') is not None

asyncio/testconnection.py:678: AssertionError ____ ServerConnectionTests.test_close_waits_for_close_frame __

self =

async def test_close_waits_for_close_frame(self):
    """close waits for a close frame (then EOF) before returning."""
    async with self.delay_frames_rcvd(MS), self.delay_eof_rcvd(MS):
        await self.connection.close()

    with self.assertRaises(ConnectionClosedOK) as raised:
        await self.connection.recv()

    exc = raised.exception
    self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
  self.assertIsNone(exc.__cause__)

E AssertionError: TimeoutError('timed out while closing connection') is not None

asyncio/test_connection.py:663: AssertionError __ ServerTests.test_close_server_keeps_connections_open ___

self =

async def test_close_server_keeps_connections_open(self):
    """Server waits for client to close open connections when closing."""
    async with serve(*args) as server:
        async with connect(get_uri(server)) as client:
            server.close(close_connections=False)

            # Server cannot receive new connections.
            await asyncio.sleep(0)
            self.assertFalse(server.sockets)

            # The server waits for the client to close the connection.
            with self.assertRaises(TimeoutError):
                async with asyncio_timeout(MS):
                    await server.wait_closed()

            # Once the client closes the connection, the server terminates.
            await client.close()
            async with asyncio_timeout(MS):
              await server.wait_closed()

asyncio/test_server.py:483:


self = <websockets.asyncio.server.Server object at 0xffffbb362670>

async def wait_closed(self) -> None:
    """
    Wait until the server is closed.

    When :meth:`wait_closed` returns, all TCP connections are closed and
    all connection handlers have returned.

    To ensure a fast shutdown, a connection handler should always be
    awaiting at least one of:

    * :meth:`~ServerConnection.recv`: when the connection is closed,
      it raises :exc:`~websockets.exceptions.ConnectionClosedOK`;
    * :meth:`~ServerConnection.wait_closed`: when the connection is
      closed, it returns.

    Then the connection handler is immediately notified of the shutdown;
    it can clean up and exit.

    """
  await asyncio.shield(self.closed_waiter)

E asyncio.exceptions.CancelledError

/home/spack/opt/spack/linux-openeuler22-aarch64/gcc-10.3.1/py-websockets-13.1-qa2xe376b2nzrshek3l3hxu4i5kgsj4x/lib/python3.8/site-packages/websockets/asyncio/server.py:492: CancelledError

During handling of the above exception, another exception occurred:

self =

async def test_close_server_keeps_connections_open(self):
    """Server waits for client to close open connections when closing."""
    async with serve(*args) as server:
        async with connect(get_uri(server)) as client:
            server.close(close_connections=False)

            # Server cannot receive new connections.
            await asyncio.sleep(0)
            self.assertFalse(server.sockets)

            # The server waits for the client to close the connection.
            with self.assertRaises(TimeoutError):
                async with asyncio_timeout(MS):
                    await server.wait_closed()

            # Once the client closes the connection, the server terminates.
            await client.close()
            async with asyncio_timeout(MS):
              await server.wait_closed()

asyncio/test_server.py:483:


/home/spack/opt/spack/linux-openeuler22-aarch64/gcc-10.3.1/py-websockets-13.1-qa2xe376b2nzrshek3l3hxu4i5kgsj4x/lib/python3.8/site-packages/websockets/asyncio/async_timeout.py:181: in aexit self._do_exit(exc_type)


self = <websockets.asyncio.async_timeout.Timeout object at 0xffffba94e950>, exc_type = <class 'asyncio.exceptions.CancelledError'>

def _do_exit(self, exc_type: Optional[Type[BaseException]]) -> None:
    if exc_type is asyncio.CancelledError and self._state == _State.TIMEOUT:
        assert self._task is not None
        _uncancel_task(self._task)
        self._timeout_handler = None
        self._task = None
      raise asyncio.TimeoutError

E asyncio.exceptions.TimeoutError

/home/spack/opt/spack/linux-openeuler22-aarch64/gcc-10.3.1/py-websockets-13.1-qa2xe376b2nzrshek3l3hxu4i5kgsj4x/lib/python3.8/site-packages/websockets/asyncio/async_timeout.py:268: TimeoutError __ ServerTests.test_close_server_keeps_handlers_running ___

self =

async def test_close_server_keeps_handlers_running(self):
    """Server waits for connection handlers to terminate."""
    async with serve(*args) as server:
        async with connect(get_uri(server) + "/delay") as client:
            # Delay termination of connection handler.
            await client.send(str(3 * MS))

            server.close()

            # The server waits for the connection handler to terminate.
            with self.assertRaises(TimeoutError):
                async with asyncio_timeout(2 * MS):
                    await server.wait_closed()

            async with asyncio_timeout(3 * MS):
              await server.wait_closed()

asyncio/test_server.py:500:


self = <websockets.asyncio.server.Server object at 0xffffbb3b4670>

async def wait_closed(self) -> None:
    """
    Wait until the server is closed.

    When :meth:`wait_closed` returns, all TCP connections are closed and
    all connection handlers have returned.

    To ensure a fast shutdown, a connection handler should always be
    awaiting at least one of:

    * :meth:`~ServerConnection.recv`: when the connection is closed,
      it raises :exc:`~websockets.exceptions.ConnectionClosedOK`;
    * :meth:`~ServerConnection.wait_closed`: when the connection is
      closed, it returns.

    Then the connection handler is immediately notified of the shutdown;
    it can clean up and exit.

    """
  await asyncio.shield(self.closed_waiter)

E asyncio.exceptions.CancelledError

/home/spack/opt/spack/linux-openeuler22-aarch64/gcc-10.3.1/py-websockets-13.1-qa2xe376b2nzrshek3l3hxu4i5kgsj4x/lib/python3.8/site-packages/websockets/asyncio/server.py:492: CancelledError

During handling of the above exception, another exception occurred:

self =

async def test_close_server_keeps_handlers_running(self):
    """Server waits for connection handlers to terminate."""
    async with serve(*args) as server:
        async with connect(get_uri(server) + "/delay") as client:
            # Delay termination of connection handler.
            await client.send(str(3 * MS))

            server.close()

            # The server waits for the connection handler to terminate.
            with self.assertRaises(TimeoutError):
                async with asyncio_timeout(2 * MS):
                    await server.wait_closed()

            async with asyncio_timeout(3 * MS):
              await server.wait_closed()

asyncio/test_server.py:500:


/home/spack/opt/spack/linux-openeuler22-aarch64/gcc-10.3.1/py-websockets-13.1-qa2xe376b2nzrshek3l3hxu4i5kgsj4x/lib/python3.8/site-packages/websockets/asyncio/async_timeout.py:181: in aexit self._do_exit(exc_type)


self = <websockets.asyncio.async_timeout.Timeout object at 0xffffbb2a1db0>, exc_type = <class 'asyncio.exceptions.CancelledError'>

def _do_exit(self, exc_type: Optional[Type[BaseException]]) -> None:
    if exc_type is asyncio.CancelledError and self._state == _State.TIMEOUT:
        assert self._task is not None
        _uncancel_task(self._task)
        self._timeout_handler = None
        self._task = None
      raise asyncio.TimeoutError

E asyncio.exceptions.TimeoutError

/home/spack/opt/spack/linux-openeuler22-aarch64/gcc-10.3.1/py-websockets-13.1-qa2xe376b2nzrshek3l3hxu4i5kgsj4x/lib/python3.8/site-packages/websockets/asyncio/async_timeout.py:268: TimeoutError ===================================================================================== short test summary info ===================================================================================== FAILED asyncio/test_client.py::ClientTests::test_keepalive_is_enabled - AssertionError: 0 not greater than 0 FAILED asyncio/test_connection.py::ClientConnectionTests::test_close_waits_for_close_frame - AssertionError: TimeoutError('timed out while closing connection') is not None FAILED asyncio/test_connection.py::ClientConnectionTests::test_close_waits_for_connection_closed - AssertionError: TimeoutError('timed out while closing connection') is not None FAILED asyncio/test_connection.py::ServerConnectionTests::test_close_waits_for_close_frame - AssertionError: TimeoutError('timed out while closing connection') is not None FAILED asyncio/test_server.py::ServerTests::test_close_server_keeps_connections_open - asyncio.exceptions.TimeoutError FAILED asyncio/test_server.py::ServerTests::test_close_server_keeps_handlers_running - asyncio.exceptions.TimeoutError

aaugustin commented 2 months ago

If I understand your report correctly — I used Google Translate — this paragraph of the documentation addresses your situation: https://websockets.readthedocs.io/en/latest/project/contributing.html#packaging

aaugustin commented 2 months ago

This discussion should be relevant: https://github.com/python-websockets/websockets/issues/1509#issuecomment-2366606121 I think it's the same cause.