comparison 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
comparison
equal deleted inserted replaced
1521:f73cc01a8167 1522:1122a90e329a
143 # The `svnserve` binary appears to use the obsolete `gethostbyname(3)` 143 # The `svnserve` binary appears to use the obsolete `gethostbyname(3)`
144 # function, which always returns an IPv4 address, even on hosts that 144 # function, which always returns an IPv4 address, even on hosts that
145 # support and expect IPv6. As a workaround, resolve the hostname 145 # support and expect IPv6. As a workaround, resolve the hostname
146 # within the test harness with `getaddrinfo(3)` to ensure that the 146 # within the test harness with `getaddrinfo(3)` to ensure that the
147 # client and server both use the same IPv4 or IPv6 address. 147 # client and server both use the same IPv4 or IPv6 address.
148 addrinfo = socket.getaddrinfo(self.host, self.port) 148 try:
149 addrinfo = socket.getaddrinfo(self.host, self.port)
150 except socket.gaierror as e:
151 # gethostname() can give a hostname that doesn't
152 # resolve. Seems bad, but let's fall back to `localhost` in
153 # that case and hope for the best.
154 self.host = 'localhost'
155 addrinfo = socket.getaddrinfo(self.host, self.port)
149 # On macOS svn seems to have issues with IPv6 at least some of 156 # On macOS svn seems to have issues with IPv6 at least some of
150 # the time, so try and bias towards IPv4. This works because 157 # the time, so try and bias towards IPv4. This works because
151 # AF_INET is less than AF_INET6 on all platforms I've 158 # AF_INET is less than AF_INET6 on all platforms I've
152 # checked. Hopefully any platform where that's not true will 159 # checked. Hopefully any platform where that's not true will
153 # be fine with IPv6 all the time. :) 160 # be fine with IPv6 all the time. :)