Mercurial > hg
comparison tests/run-tests.py @ 30886:2aaa8bfc7bd9
runtests: check ports on IPv6 address
Previously, checkportisavailable only checks ports on the IPv4 address. This
patch makes it check IPv6 as well. It'll be useful if "localhost" does not
have an IPv4 address, or its IPv4 address does not exist somehow.
author | Jun Wu <quark@fb.com> |
---|---|
date | Thu, 09 Feb 2017 05:57:54 -0800 |
parents | 3de9df6ee5bf |
children | b9116befa784 |
comparison
equal
deleted
inserted
replaced
30885:564a96a56b73 | 30886:2aaa8bfc7bd9 |
---|---|
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 def checkportisavailable(port): | 115 def checkportisavailable(port): |
116 """return true if a port seems free to bind on localhost""" | 116 """return true if a port seems free to bind on localhost""" |
117 try: | 117 families = [getattr(socket, i, None) |
118 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 118 for i in ('AF_INET', 'AF_INET6') |
119 s.bind(('localhost', port)) | 119 if getattr(socket, i, None) is not None] |
120 s.close() | 120 for family in families: |
121 return True | 121 try: |
122 except socket.error as exc: | 122 s = socket.socket(family, socket.SOCK_STREAM) |
123 if not exc.errno == errno.EADDRINUSE: | 123 s.bind(('localhost', port)) |
124 raise | 124 s.close() |
125 return False | 125 return True |
126 except socket.error as exc: | |
127 if exc.errno not in (errno.EADDRINUSE, errno.EADDRNOTAVAIL): | |
128 raise | |
129 return False | |
126 | 130 |
127 closefds = os.name == 'posix' | 131 closefds = os.name == 'posix' |
128 def Popen4(cmd, wd, timeout, env=None): | 132 def Popen4(cmd, wd, timeout, env=None): |
129 processlock.acquire() | 133 processlock.acquire() |
130 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env, | 134 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env, |