comparison tests/run-tests.py @ 31002:a489ee9b2852

runtests: prefer IPv4 to IPv6 To make IPv6 work, there are multiple areas that need to fix. Before they all get fixed, use IPv4 by default. This should fix tests caused on IPv6 systems.
author Jun Wu <quark@fb.com>
date Fri, 17 Feb 2017 00:59:09 -0800
parents 1ee685defe80
children 225f574e0645
comparison
equal deleted inserted replaced
31001:e7eca6e1372e 31002:a489ee9b2852
111 111
112 # For Windows support 112 # For Windows support
113 wifexited = getattr(os, "WIFEXITED", lambda x: False) 113 wifexited = getattr(os, "WIFEXITED", lambda x: False)
114 114
115 # Whether to use IPv6 115 # Whether to use IPv6
116 def checkipv6available(port=20058): 116 def checksocketfamily(name, port=20058):
117 """return true if we can listen on localhost's IPv6 ports""" 117 """return true if we can listen on localhost using family=name
118 family = getattr(socket, 'AF_INET6', None) 118
119 name should be either 'AF_INET', or 'AF_INET6'.
120 port being used is okay - EADDRINUSE is considered as successful.
121 """
122 family = getattr(socket, name, None)
119 if family is None: 123 if family is None:
120 return False 124 return False
121 try: 125 try:
122 s = socket.socket(family, socket.SOCK_STREAM) 126 s = socket.socket(family, socket.SOCK_STREAM)
123 s.bind(('localhost', port)) 127 s.bind(('localhost', port))
131 else: 135 else:
132 raise 136 raise
133 else: 137 else:
134 return False 138 return False
135 139
136 useipv6 = checkipv6available() 140 # IPv6 is used if IPv4 is not available and IPv6 is available.
141 useipv6 = (not checksocketfamily('AF_INET')) and checksocketfamily('AF_INET6')
137 142
138 def checkportisavailable(port): 143 def checkportisavailable(port):
139 """return true if a port seems free to bind on localhost""" 144 """return true if a port seems free to bind on localhost"""
140 if useipv6: 145 if useipv6:
141 family = socket.AF_INET6 146 family = socket.AF_INET6