diff options
Diffstat (limited to 'tests/test_push_command.py')
-rw-r--r-- | tests/test_push_command.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/test_push_command.py b/tests/test_push_command.py index a62f3ce..6debbb2 100644 --- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -138,7 +138,33 @@ class PushTests(test_util.TestBase): open(os.path.join(repo_path, 'conf', 'svnserve.conf'), 'w').write('[general]\nanon-access=write\n[sasl]\n') self.port = random.randint(socket.IPPORT_USERRESERVED, 65535) - self.host = 'localhost' + 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) + # On macOS svn seems to have issues with IPv6 at least some of + # the time, so try and bias towards IPv4. This works because + # AF_INET is less than AF_INET6 on all platforms I've + # checked. Hopefully any platform where that's not true will + # be fine with IPv6 all the time. :) + selected = sorted(addrinfo)[0] + self.host = selected[4][0] + + # If we're connecting via IPv6 the need to put brackets around the + # hostname in the URL. + ipv6 = selected[0] == socket.AF_INET6 + + # Ditch any interface information since that's not helpful in + # a URL + if ipv6 and ':' in self.host and '%' in self.host: + self.host = self.host.rsplit('%', 1)[0] + + 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 +178,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 |