# HG changeset patch # User Arun Kulshreshtha # Date 1491868708 25200 # Node ID 6e3f48d8002fb8af9057b4a469b7ef8f8ca51700 # Parent f75c1d112793d1380f30a1439256395402d15b02 tests: fix ipv6 support in test_push_command.py This test runs the `svnserve` binary, which appears to resolve the hostname passed as an argument using gethostbyname(3), which can only return an IPv4 address. When run on a system that is configured to only have an IPv6 address, Mercurial will correctly resolve the hostname to an IPv6 address, but the SVN server will be listening on an incorrect IPv4 address, causing the test to fail. The workaround is to resolve the hostname using getaddrinfo(3) in the test harness and pass the resulting address to svnserve. diff --git a/tests/test_push_command.py b/tests/test_push_command.py --- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -139,6 +139,20 @@ class PushTests(test_util.TestBase): 'w').write('[general]\nanon-access=write\n[sasl]\n') self.port = random.randint(socket.IPPORT_USERRESERVED, 65535) self.host = socket.gethostname() + + # The `svnserve` binary appears to use the obsolete `gethostbyname(3)` + # function, which always returns an IPv4 address, even on hosts that + # support and expect IPv6. As a workaround, resolve the hostname + # within the test harness with `getaddrinfo(3)` to ensure that the + # client and server both use the same IPv4 or IPv6 address. + addrinfo = socket.getaddrinfo(self.host, self.port) + self.host = addrinfo[0][4][0] + + # If we're connecting via IPv6 the need to put brackets around the + # hostname in the URL. + ipv6 = addrinfo[0][0] == socket.AF_INET6 + urlfmt = 'svn://[%s]:%d/%s' if ipv6 else 'svn://%s:%d/%s' + args = ['svnserve', '--daemon', '--foreground', '--listen-port=%d' % self.port, '--listen-host=%s' % self.host, @@ -152,7 +166,7 @@ class PushTests(test_util.TestBase): import shutil shutil.rmtree(self.wc_path) commands.clone(self.ui(), - 'svn://%s:%d/%s' % (self.host, self.port, subdir), + urlfmt % (self.host, self.port, subdir), self.wc_path, noupdate=True) repo = self.repo