irmen / Pyro5

Pyro 5 - Python remote objects
https://pyro5.readthedocs.io
MIT License
303 stars 36 forks source link

Test failing with Pyro5 5.15 #82

Closed ceamac closed 10 months ago

ceamac commented 10 months ago

One test can fail because it assumes "localhost" is always IPv4. I have this in my /etc/hosts (debian system):

127.0.0.1   localhost

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

And it resolves "localhost" to IPv6. For example:

$ ping localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.022 ms
...

tests/test_socketutil.py::TestSocketutil::testGetInterface FAILED

======================================================================================================================================== FAILURES ========================================================================================================================================
____________________________________________________________________________________________________________________________ TestSocketutil.testGetInterface _____________________________________________________________________________________________________________________________

self = <test_socketutil.TestSocketutil object at 0x7f15404b5150>

    def testGetInterface(self):
        addr = socketutil.get_interface("localhost")
>       assert addr.version == 4
E       AssertionError: assert 6 == 4
E        +  where 6 = IPv6Interface('::1/128').version

addr       = IPv6Interface('::1/128')
self       = <test_socketutil.TestSocketutil object at 0x7f15404b5150>

tests/test_socketutil.py:59: AssertionError
==================================================================================================================================== warnings summary ====================================================================================================================================
tests/test_daemon.py::TestDaemon::testDaemonConnectedSocket
  /var/tmp/portage/dev-python/Pyro5-5.15/work/Pyro5-5.15/tests/test_daemon.py:106: ResourceWarning: unclosed <socket.socket fd=16, family=1, type=1, proto=0>
    s1, s2 = socket.socketpair()
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/test_daemon.py::TestDaemon::testDaemonConnectedSocket
  /usr/lib/python3.11/site-packages/_pytest/python.py:194: ResourceWarning: unclosed <socket.socket fd=17, family=1, type=1, proto=0>
    result = testfunction(**testargs)
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/test_server.py::TestServerMultiplexNoTimeout::testConnectionStuff
  /var/tmp/portage/dev-python/Pyro5-5.15/work/Pyro5-5.15/Pyro5/socketutil.py:419: ResourceWarning: unclosed <socket.socket fd=34, family=10, type=1, proto=0, laddr=('::1', 50038, 0, 0), raddr=('::1', 36735, 0, 0)>
    self.tracked_resources = weakref.WeakSet()   # type: weakref.WeakSet[Any]  # weakrefs to resources for this connection
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/test_server.py::TestServerMultiplexNoTimeout::testException
  /usr/lib/python3.11/threading.py:597: ResourceWarning: unclosed <socket.socket fd=33, family=10, type=1, proto=0, laddr=('::1', 58966, 0, 0), raddr=('::1', 46679, 0, 0)>
    with self._cond:
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/test_server.py::TestServerMultiplexNoTimeout::testException
  /usr/lib/python3.11/threading.py:597: ResourceWarning: unclosed <socket.socket fd=34, family=10, type=1, proto=0, laddr=('::1', 34752, 0, 0), raddr=('::1', 45761, 0, 0)>
    with self._cond:
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/test_server_timeout.py::TestServerMultiplexTimeout::testReconnectAndCompression
  /var/tmp/portage/dev-python/Pyro5-5.15/work/Pyro5-5.15/Pyro5/serializers.py:290: ResourceWarning: unclosed <socket.socket fd=11, family=10, type=1, proto=0, laddr=('::1', 51478, 0, 0), raddr=('::1', 41891, 0, 0)>
    return self.recreate_classes(serpent.loads(data))
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================================================================ short test summary info =================================================================================================================================
FAILED tests/test_socketutil.py::TestSocketutil::testGetInterface - AssertionError: assert 6 == 4

If I replace addr = socketutil.get_interface("localhost") with addr = socketutil.get_interface("127.0.0.1"), the test passes.

irmen commented 10 months ago

Odd, this doesn't fail on my own system (Arch) with ipv6 But maybe making the test more robust is the right thing to do.

irmen commented 10 months ago

Allright, made a different improvement to the test that should make it still use localhost but know about ipv6 8db91b617dd08508053e54dea2a781749a00ffc8 This should also fix your issue.

ceamac commented 10 months ago

I can confirm the test passes. Thank you!