changeset 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 f73cc01a8167
children 83b28c179d19
files tests/test_push_command.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
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