runtests: prefer IPv4 to IPv6
authorJun Wu <quark@fb.com>
Fri, 17 Feb 2017 00:59:09 -0800
changeset 31002 a489ee9b2852
parent 31001 e7eca6e1372e
child 31003 225f574e0645
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.
tests/run-tests.py
--- a/tests/run-tests.py	Fri Feb 17 11:08:36 2017 +0100
+++ b/tests/run-tests.py	Fri Feb 17 00:59:09 2017 -0800
@@ -113,9 +113,13 @@
 wifexited = getattr(os, "WIFEXITED", lambda x: False)
 
 # Whether to use IPv6
-def checkipv6available(port=20058):
-    """return true if we can listen on localhost's IPv6 ports"""
-    family = getattr(socket, 'AF_INET6', None)
+def checksocketfamily(name, port=20058):
+    """return true if we can listen on localhost using family=name
+
+    name should be either 'AF_INET', or 'AF_INET6'.
+    port being used is okay - EADDRINUSE is considered as successful.
+    """
+    family = getattr(socket, name, None)
     if family is None:
         return False
     try:
@@ -133,7 +137,8 @@
     else:
         return False
 
-useipv6 = checkipv6available()
+# IPv6 is used if IPv4 is not available and IPv6 is available.
+useipv6 = (not checksocketfamily('AF_INET')) and checksocketfamily('AF_INET6')
 
 def checkportisavailable(port):
     """return true if a port seems free to bind on localhost"""