From 6cd282bcedc3c62766476b2e2bc5885d0127f609 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 10 Jul 2016 20:05:49 +0530 Subject: [PATCH] Ignore conn closed/reset errors for all invalid data web socket tests --- src/calibre/srv/tests/http.py | 4 ++-- src/calibre/srv/tests/web_sockets.py | 34 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/calibre/srv/tests/http.py b/src/calibre/srv/tests/http.py index 407e47df49..62a98f16d6 100644 --- a/src/calibre/srv/tests/http.py +++ b/src/calibre/srv/tests/http.py @@ -189,7 +189,7 @@ class TestHTTP(BaseTest): self.ae('', r.read()) server.change_handler(lambda data:data.path[0] + data.read().decode('ascii')) - conn = server.connect() + conn = server.connect(timeout=1) # Test simple GET conn.request('GET', '/test/') @@ -291,7 +291,7 @@ class TestHTTP(BaseTest): def handler(conn): return conn.generate_static_output('test', lambda : ''.join(conn.path)) with NamedTemporaryFile(suffix='test.epub') as f, open(P('localization/locales.zip'), 'rb') as lf, \ - TestServer(handler, timeout=0.2, compress_min_size=0) as server: + TestServer(handler, timeout=1, compress_min_size=0) as server: fdata = string.ascii_letters * 100 f.write(fdata), f.seek(0) diff --git a/src/calibre/srv/tests/web_sockets.py b/src/calibre/srv/tests/web_sockets.py index 1aa884ff41..1faa31bfd7 100644 --- a/src/calibre/srv/tests/web_sockets.py +++ b/src/calibre/srv/tests/web_sockets.py @@ -214,39 +214,39 @@ class WebSocketTest(BaseTest): fragments = 'Hello-µ@ßöä üàá-UTF-8!!'.split() nc = struct.pack(b'!H', NORMAL_CLOSE) + def ic_test(*args, **kwargs): + try: + simple_test(*args, **kwargs) + except socket.error as err: + if err.errno not in (errno.EPIPE, errno.ECONNRESET): + # This is raised on OS X occassionally, when the server + # closes the connection before the client has finished + # writing all data. + raise + with server.silence_log: for rsv in xrange(1, 7): - simple_test([{'rsv':rsv, 'opcode':BINARY}], [], close_code=PROTOCOL_ERROR, send_close=False) + ic_test([{'rsv':rsv, 'opcode':BINARY}], [], close_code=PROTOCOL_ERROR, send_close=False) for opcode in (3, 4, 5, 6, 7, 11, 12, 13, 14, 15): - simple_test([{'opcode':opcode}], [], close_code=PROTOCOL_ERROR, send_close=False) + ic_test([{'opcode':opcode}], [], close_code=PROTOCOL_ERROR, send_close=False) for opcode in (PING, PONG): - simple_test([ + ic_test([ {'opcode':opcode, 'payload':'f1', 'fin':0}, {'opcode':opcode, 'payload':'f2'} ], close_code=PROTOCOL_ERROR, send_close=False) - simple_test([(CLOSE, nc + b'x'*124)], send_close=False, close_code=PROTOCOL_ERROR) + ic_test([(CLOSE, nc + b'x'*124)], send_close=False, close_code=PROTOCOL_ERROR) for fin in (0, 1): - simple_test([{'opcode':0, 'fin': fin, 'payload':b'non-continuation frame'}, 'some text'], close_code=PROTOCOL_ERROR, send_close=False) + ic_test([{'opcode':0, 'fin': fin, 'payload':b'non-continuation frame'}, 'some text'], close_code=PROTOCOL_ERROR, send_close=False) - simple_test([ + ic_test([ {'opcode':TEXT, 'payload':fragments[0], 'fin':0}, {'opcode':CONTINUATION, 'payload':fragments[1]}, {'opcode':0, 'fin':0} ], [''.join(fragments)], close_code=PROTOCOL_ERROR, send_close=False) - simple_test([ + ic_test([ {'opcode':TEXT, 'payload':fragments[0], 'fin':0}, {'opcode':TEXT, 'payload':fragments[1]}, ], close_code=PROTOCOL_ERROR, send_close=False) - def ic_test(*args, **kwargs): - try: - simple_test(*args, **kwargs) - except socket.error as err: - if err.errno not in (errno.EPIPE, errno.ECONNRESET): - # This is raised on OS X occassionally, when the server - # closes the connection before the client has finished - # writing all data. - raise - frags = [] for payload in (b'\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5', b'\xed\xa0\x80', b'\x80\x65\x64\x69\x74\x65\x64'): frags.append({'opcode':(CONTINUATION if frags else TEXT), 'fin':1 if len(frags) == 2 else 0, 'payload':payload})