diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2013-11-17 11:12:56 +0200 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-11-17 22:06:04 +0200 |
commit | d53acffe62709a12104d43f665fe496ab768f4bf (patch) | |
tree | 62bd071943860e762f48535de7510b034e5143b3 | |
parent | 1ee42ca288ac5def839833013ae0795b666953f3 (diff) |
Fix test browser.test_chunked_synchronous_xhr on Windows. It failed due to a name visibility issue in pickling, see http://stackoverflow.com/questions/8126654/using-multiprocessing-inside-decorator-generates-error-cant-pickle-function?rq=1 , which is fixed by hoisting the process start function to global scope.
-rw-r--r-- | tests/test_browser.py | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/tests/test_browser.py b/tests/test_browser.py index 12a08fe3..daf82a76 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1,4 +1,4 @@ -import BaseHTTPServer, multiprocessing, os, shutil, subprocess, unittest +import BaseHTTPServer, multiprocessing, os, shutil, subprocess, unittest, zlib from runner import BrowserCore, path_from_root from tools.shared import * @@ -8,6 +8,45 @@ def run_in_other_browser(url): webbrowser.open_new = run_in_other_browser ''' +def test_chunked_synchronous_xhr_server(support_byte_ranges, chunkSize, data, checksum): + class ChunkedServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): + def sendheaders(s, extra=[], length=len(data)): + s.send_response(200) + s.send_header("Content-Length", str(length)) + s.send_header("Access-Control-Allow-Origin", "http://localhost:8888") + s.send_header("Access-Control-Expose-Headers", "Content-Length, Accept-Ranges") + s.send_header("Content-type", "application/octet-stream") + if support_byte_ranges: + s.send_header("Accept-Ranges", "bytes") + for i in extra: + s.send_header(i[0], i[1]) + s.end_headers() + + def do_HEAD(s): + s.sendheaders() + + def do_OPTIONS(s): + s.sendheaders([("Access-Control-Allow-Headers", "Range")], 0) + + def do_GET(s): + if not support_byte_ranges: + s.sendheaders() + s.wfile.write(data) + else: + (start, end) = s.headers.get("range").split("=")[1].split("-") + start = int(start) + end = int(end) + end = min(len(data)-1, end) + length = end-start+1 + s.sendheaders([],length) + s.wfile.write(data[start:end+1]) + s.wfile.close() + + expectedConns = 11 + httpd = BaseHTTPServer.HTTPServer(('localhost', 11111), ChunkedServerHandler) + for i in range(expectedConns+1): + httpd.handle_request() + class browser(BrowserCore): @staticmethod def audio(): @@ -1265,51 +1304,15 @@ keydown(100);keyup(100); // trigger the end chunkSize = 1024 data = os.urandom(10*chunkSize+1) # 10 full chunks and one 1 byte chunk - expectedConns = 11 - import zlib checksum = zlib.adler32(data) - def chunked_server(support_byte_ranges): - class ChunkedServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): - def sendheaders(s, extra=[], length=len(data)): - s.send_response(200) - s.send_header("Content-Length", str(length)) - s.send_header("Access-Control-Allow-Origin", "http://localhost:8888") - s.send_header("Access-Control-Expose-Headers", "Content-Length, Accept-Ranges") - s.send_header("Content-type", "application/octet-stream") - if support_byte_ranges: - s.send_header("Accept-Ranges", "bytes") - for i in extra: - s.send_header(i[0], i[1]) - s.end_headers() - - def do_HEAD(s): - s.sendheaders() - - def do_OPTIONS(s): - s.sendheaders([("Access-Control-Allow-Headers", "Range")], 0) - - def do_GET(s): - if not support_byte_ranges: - s.sendheaders() - s.wfile.write(data) - else: - (start, end) = s.headers.get("range").split("=")[1].split("-") - start = int(start) - end = int(end) - end = min(len(data)-1, end) - length = end-start+1 - s.sendheaders([],length) - s.wfile.write(data[start:end+1]) - s.wfile.close() - httpd = BaseHTTPServer.HTTPServer(('localhost', 11111), ChunkedServerHandler) - for i in range(expectedConns+1): - httpd.handle_request() - - server = multiprocessing.Process(target=chunked_server, args=(True,)) + server = multiprocessing.Process(target=test_chunked_synchronous_xhr_server, args=(True,chunkSize,data,checksum,)) server.start() self.run_browser(main, 'Chunked binary synchronous XHR in Web Workers!', '/report_result?' + str(checksum)) server.terminate() + # Avoid race condition on cleanup, wait a bit so that processes have released file locks so that test tearDown won't + # attempt to rmdir() files in use. + time.sleep(2) def test_glgears(self): self.btest('hello_world_gles.c', reference='gears.png', reference_slack=1, |