summaryrefslogtreecommitdiff
path: root/tools/http_server.py
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-11-19 18:56:37 +0100
committerRy Dahl <ry@tinyclouds.org>2019-11-19 12:56:37 -0500
commit2ac107f54848e44144c0ee2bdbdfb40732e20b2b (patch)
tree03bae2b3753542ce15341e5a109e125d0eb542b2 /tools/http_server.py
parente73a82dc42b3d80bea42482e227c31e5ef01e273 (diff)
fix: use AF_INET6 in ./tools/http_server.py (#3374)
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-xtools/http_server.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/tools/http_server.py b/tools/http_server.py
index 76efab73b..f15c053ae 100755
--- a/tools/http_server.py
+++ b/tools/http_server.py
@@ -7,6 +7,7 @@ from contextlib import contextmanager
import os
import SimpleHTTPServer
import SocketServer
+import socket
import sys
from time import sleep
from threading import Thread
@@ -105,6 +106,17 @@ class ContentTypeHandler(QuietSimpleHTTPRequestHandler):
RunningServer = namedtuple("RunningServer", ["server", "thread"])
+def get_socket(port, handler):
+ SocketServer.TCPServer.allow_reuse_address = True
+ if os.name != "nt":
+ # We use AF_INET6 to avoid flaky test issue, particularly with
+ # the test 019_media_types. It's not well understood why this fixes the
+ # flaky tests, but it does appear to...
+ # See https://github.com/denoland/deno/issues/3332
+ SocketServer.TCPServer.address_family = socket.AF_INET6
+ return SocketServer.TCPServer(("", port), handler)
+
+
def server():
os.chdir(root_path) # Hopefully the main thread doesn't also chdir.
Handler = ContentTypeHandler
@@ -115,8 +127,7 @@ def server():
".jsx": "application/javascript",
".json": "application/json",
})
- SocketServer.TCPServer.allow_reuse_address = True
- s = SocketServer.TCPServer(("", PORT), Handler)
+ s = get_socket(PORT, Handler)
if not QUIET:
print "Deno test server http://localhost:%d/" % PORT
return RunningServer(s, start(s))
@@ -133,9 +144,7 @@ def base_redirect_server(host_port, target_port, extra_path_segment=""):
target_host + extra_path_segment + self.path)
self.end_headers()
- Handler = RedirectHandler
- SocketServer.TCPServer.allow_reuse_address = True
- s = SocketServer.TCPServer(("", host_port), Handler)
+ s = get_socket(host_port, RedirectHandler)
if not QUIET:
print "redirect server http://localhost:%d/ -> http://localhost:%d/" % (
host_port, target_port)