Mercurial > hgsubversion
diff tests/test_push_command.py @ 1522:1122a90e329a
test_push_command: deal with gethostname() sometimes returning bad hostnames
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 25 Oct 2017 15:30:34 -0400 |
parents | 5441a9d1fd50 |
children | 0ebcc5bbf692 |
line wrap: on
line diff
--- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -145,7 +145,14 @@ class PushTests(test_util.TestBase): # 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) + try: + addrinfo = socket.getaddrinfo(self.host, self.port) + except socket.gaierror as e: + # gethostname() can give a hostname that doesn't + # resolve. Seems bad, but let's fall back to `localhost` in + # that case and hope for the best. + self.host = 'localhost' + 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