# HG changeset patch
# User Jun Wu <qu...@fb.com>
# Date 1487321949 28800
#      Fri Feb 17 00:59:09 2017 -0800
# Node ID 85e1f03110abeaab9a82517f5716a1cab7044042
# Parent  3844b3299a53b3746e1a708c84bbd6b83adddb7d
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 85e1f03110ab
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.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -114,7 +114,11 @@ wifexited = getattr(os, "WIFEXITED", lam
 
 # 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
@@ -134,5 +138,6 @@ def checkipv6available(port=20058):
         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):
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to