From 2ac107f54848e44144c0ee2bdbdfb40732e20b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 19 Nov 2019 18:56:37 +0100 Subject: [PATCH] fix: use AF_INET6 in ./tools/http_server.py (#3374) --- cli/tests/integration_tests.rs | 12 ------------ tools/http_server.py | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 2bb577fbbd..195202d49c 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -156,13 +156,11 @@ itest!(_018_async_catch { output: "018_async_catch.ts.out", }); -/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally. itest!(_019_media_types { args: "run --reload 019_media_types.ts", output: "019_media_types.ts.out", http_server: true, }); -*/ itest!(_020_json_modules { args: "run --reload 020_json_modules.ts", @@ -174,13 +172,11 @@ itest!(_021_mjs_modules { output: "021_mjs_modules.ts.out", }); -/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally. itest!(_022_info_flag_script { args: "info http://127.0.0.1:4545/cli/tests/019_media_types.ts", output: "022_info_flag_script.out", http_server: true, }); -*/ itest!(_023_no_ext_with_headers { args: "run --reload 023_no_ext_with_headers", @@ -337,21 +333,17 @@ itest!(_047_jsx { output: "047_jsx_test.jsx.out", }); -/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally. itest!(_048_media_types_jsx { args: "run --reload 048_media_types_jsx.ts", output: "048_media_types_jsx.ts.out", http_server: true, }); -*/ -/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally. itest!(_049_info_flag_script_jsx { args: "info http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts", output: "049_info_flag_script_jsx.out", http_server: true, }); -*/ itest!(_050_more_jsons { args: "run --reload 050_more_jsons.ts", @@ -370,13 +362,11 @@ itest!(lock_check_ok { http_server: true, }); -/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally. itest!(lock_check_ok2 { args: "run 019_media_types.ts --lock=lock_check_ok2.json", output: "019_media_types.ts.out", http_server: true, }); -*/ itest!(lock_check_err { args: "run --lock=lock_check_err.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts", @@ -386,7 +376,6 @@ itest!(lock_check_err { http_server: true, }); -/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally. itest!(lock_check_err2 { args: "run 019_media_types.ts --lock=lock_check_err2.json", output: "lock_check_err2.out", @@ -394,7 +383,6 @@ itest!(lock_check_err2 { exit_code: 10, http_server: true, }); -*/ itest!(async_error { exit_code: 1, diff --git a/tools/http_server.py b/tools/http_server.py index 76efab73bd..f15c053aea 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)