summaryrefslogtreecommitdiff
path: root/tools/http_server.py
diff options
context:
space:
mode:
authorAndy Hayden <andyhayden1@gmail.com>2019-06-08 04:46:57 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-06-08 07:46:57 -0400
commit5960e398ecab914effec821cc6da5f3a091fdb50 (patch)
treebb12c155ef59b725dcc0d7a32b757e47718cdaa1 /tools/http_server.py
parent4ea2df6759abf3a99e07fe720987805075c8a18b (diff)
make tests quieter (#2468)
Don't mix every http request in with the tests output. Don't print that the file servers are starting unless -vv flag is passed. Capture the output of run with run_output which returns stdout, stderr and exit_code. Test against this rather than relying on sys.exit.
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-xtools/http_server.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/tools/http_server.py b/tools/http_server.py
index 7415ee47c..116169e2f 100755
--- a/tools/http_server.py
+++ b/tools/http_server.py
@@ -17,8 +17,17 @@ REDIRECT_PORT = 4546
ANOTHER_REDIRECT_PORT = 4547
DOUBLE_REDIRECTS_PORT = 4548
+QUIET = '-v' not in sys.argv and '--verbose' not in sys.argv
-class ContentTypeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+
+class QuietSimpleHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+ def log_request(self, code='-', size='-'):
+ if not QUIET:
+ SimpleHTTPServer.SimpleHTTPRequestHandler.log_request(
+ self, code, size)
+
+
+class ContentTypeHandler(QuietSimpleHTTPRequestHandler):
def do_GET(self):
if "multipart_form_data.txt" in self.path:
self.protocol_version = 'HTTP/1.1'
@@ -102,7 +111,8 @@ def server():
})
SocketServer.TCPServer.allow_reuse_address = True
s = SocketServer.TCPServer(("", PORT), Handler)
- print "Deno test server http://localhost:%d/" % PORT
+ if not QUIET:
+ print "Deno test server http://localhost:%d/" % PORT
return RunningServer(s, start(s))
@@ -110,7 +120,7 @@ def base_redirect_server(host_port, target_port, extra_path_segment=""):
os.chdir(root_path)
target_host = "http://localhost:%d" % target_port
- class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+ class RedirectHandler(QuietSimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(301)
self.send_header('Location',
@@ -120,8 +130,9 @@ def base_redirect_server(host_port, target_port, extra_path_segment=""):
Handler = RedirectHandler
SocketServer.TCPServer.allow_reuse_address = True
s = SocketServer.TCPServer(("", host_port), Handler)
- print "redirect server http://localhost:%d/ -> http://localhost:%d/" % (
- host_port, target_port)
+ if not QUIET:
+ print "redirect server http://localhost:%d/ -> http://localhost:%d/" % (
+ host_port, target_port)
return RunningServer(s, start(s))
@@ -153,7 +164,8 @@ def start(s):
def spawn():
servers = (server(), redirect_server(), another_redirect_server(),
double_redirects_server())
- sleep(1) # TODO I'm too lazy to figure out how to do this properly.
+ while any(not s.thread.is_alive() for s in servers):
+ sleep(0.01)
try:
yield
finally: