Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: util/net/http_transport_test_server.py

Issue 1286173007: HTTPTransport test: Deal with limited-size pipe buffers (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/net/http_transport_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/net/http_transport_test_server.py
diff --git a/util/net/http_transport_test_server.py b/util/net/http_transport_test_server.py
index ecf71d702fe7922ef1bef3269f22a40838662bba..4558f0f5820aea415cc4f58587695960c378dcaf 100755
--- a/util/net/http_transport_test_server.py
+++ b/util/net/http_transport_test_server.py
@@ -58,6 +58,14 @@ class BufferedReadFile(object):
self.file.close()
+# Everything to be written to stdout is collected into this string. It can’t be
+# written to stdout until after the HTTP transaction is complete, because
+# stdout is a pipe being read by a test program that’s also the HTTP client. The
+# test program expects to complete the entire HTTP transaction before it even
+# starts reading this script’s stdout. If the stdout pipe buffer fills up during
+# an HTTP transaction, deadlock would result.
+to_write_to_stdout = ''
Mark Mentovai 2015/08/18 21:26:19 I don’t like that this is a global, but BaseHTTPSe
Robert Sesek 2015/08/18 21:42:49 You could move it to RequestHandler.written_respon
+
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
response_code = 500
response_body = ''
@@ -69,9 +77,9 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
BaseHTTPServer.BaseHTTPRequestHandler.handle_one_request(self)
def do_POST(self):
- writer = sys.stdout
+ global to_write_to_stdout
- writer.write(self.rfile.buffer)
+ to_write_to_stdout = self.rfile.buffer
self.rfile.buffer = ''
if self.headers.get('Transfer-Encoding', '') == 'Chunked':
@@ -80,15 +88,14 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
length = int(self.headers.get('Content-Length', -1))
body = self.rfile.read(length)
+ to_write_to_stdout += body
+
self.send_response(self.response_code)
self.end_headers()
if self.response_code == 200:
self.wfile.write(self.response_body)
self.wfile.write('\r\n')
- writer.write(body)
- writer.flush()
-
def handle_chunked_encoding(self):
"""This parses a "Transfer-Encoding: Chunked" body in accordance with
RFC 7230 §4.1. This returns the result as a string.
@@ -146,5 +153,9 @@ def Main():
# Handle the request.
server.handle_request()
+ # Share the entire request with the test program, which will validate it.
+ sys.stdout.write(to_write_to_stdout)
+ sys.stdout.flush()
+
if __name__ == '__main__':
Main()
« no previous file with comments | « util/net/http_transport_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698