novnc / websockify

Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tests failed on macos

natsukium opened this issue · comments

Hi, thank you for developing websockify and novnc.
It is very useful.

I now run the unit tests on macos but got the following error.

error log
============================= test session starts ==============================
platform darwin -- Python 3.10.10, pytest-7.2.0, pluggy-1.0.0
rootdir: /private/tmp/nix-build-python3.10-websockify-0.11.0.drv-0/source
collected 64 items                                                             

tests/test_auth_plugins.py ....                                          [  6%]
tests/test_token_plugins.py .............                                [ 26%]
tests/test_websocket.py .................                                [ 53%]
tests/test_websocketproxy.py .....                                       [ 60%]
tests/test_websocketserver.py .....                                      [ 68%]
tests/test_websockifyserver.py ................F...                      [100%]

=================================== FAILURES ===================================
__________ WebSockifyServerTestCase.test_socket_set_keepalive_options __________

self = <test_websockifyserver.WebSockifyServerTestCase testMethod=test_socket_set_keepalive_options>

    def test_socket_set_keepalive_options(self):
        keepcnt = 12
        keepidle = 34
        keepintvl = 56
    
        server = self._get_server(daemon=False, ssl_only=0, idle_timeout=1)
>       sock = server.socket('localhost',
                             tcp_keepcnt=keepcnt,
                             tcp_keepidle=keepidle,
                             tcp_keepintvl=keepintvl)

tests/test_websockifyserver.py:375: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

host = 'localhost', port = None, connect = False, prefer_ipv6 = False
unix_socket = None, use_ssl = False, tcp_keepalive = True, tcp_keepcnt = 12
tcp_keepidle = 34, tcp_keepintvl = 56

    @staticmethod
    def socket(host, port=None, connect=False, prefer_ipv6=False,
               unix_socket=None, use_ssl=False, tcp_keepalive=True,
               tcp_keepcnt=None, tcp_keepidle=None, tcp_keepintvl=None):
        """ Resolve a host (and optional port) to an IPv4 or IPv6
        address. Create a socket. Bind to it if listen is set,
        otherwise connect to it. Return the socket.
        """
        flags = 0
        if host == '':
            host = None
        if connect and not (port or unix_socket):
            raise Exception("Connect mode requires a port")
        if use_ssl and not ssl:
            raise Exception("SSL socket requested but Python SSL module not loaded.");
        if not connect and use_ssl:
            raise Exception("SSL only supported in connect mode (for now)")
        if not connect:
            flags = flags | socket.AI_PASSIVE
    
        if not unix_socket:
            addrs = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM,
                    socket.IPPROTO_TCP, flags)
            if not addrs:
                raise Exception("Could not resolve host '%s'" % host)
            addrs.sort(key=lambda x: x[0])
            if prefer_ipv6:
                addrs.reverse()
            sock = socket.socket(addrs[0][0], addrs[0][1])
    
            if  tcp_keepalive:
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
                if tcp_keepcnt:
                    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT,
                                    tcp_keepcnt)
                if tcp_keepidle:
>                   sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE,
                                    tcp_keepidle)
E                   AttributeError: module 'socket' has no attribute 'TCP_KEEPIDLE'. Did you mean: 'TCP_KEEPALIVE'?

websockify/websockifyserver.py:458: AttributeError
=============================== warnings summary ===============================
websockify/token_plugins.py:39
  /private/tmp/nix-build-python3.10-websockify-0.11.0.drv-0/source/websockify/token_plugins.py:39: DeprecationWarning: invalid escape sequence '\s'
    tok, target = re.split(':\s', line)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_websockifyserver.py::WebSockifyServerTestCase::test_socket_set_keepalive_options - AttributeError: module 'socket' has no attribute 'TCP_KEEPIDLE'. Did you me...
=================== 1 failed, 63 passed, 1 warning in 2.24s ====================

socket.TCP_KEEPIDLE is not defined on macos, and I suppose it would be better to use socket.TCP_KEEPALIVE on Python 3.10 and above on macos. (https://docs.python.org/3/library/socket.html#constants)
For Python 3.9 and below, it would be better to check the attribute and skip the test, like TCP_KEEPCNT.

I know little about sockets, so that I may be wrong, but I'd be happy to check.