diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index 6cc4a06..179881d 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -160,6 +160,18 @@ class ConnectionClosed(Exception): pass +def send_expect_close(sock, buf): + # Some tests will induce behavior that causes the remote end to + # close the connection before all of the data has been written. + # With small kernel buffer sizes, this can cause an EPIPE error. + # Since the test expects an early close, this can be ignored. + try: + sock.sendall(buf) + except socket.error as exc: + if support.get_errno(exc) != errno.EPIPE: + raise + + def read_http(sock): fd = sock.makefile('rb') try: @@ -336,10 +348,9 @@ class TestHttpd(_TestBase): for ii in range(3000): path_parts.append('path') path = '/'.join(path_parts) - request = ('GET /%s HTTP/1.0\r\nHost: localhost\r\n\r\n' % path).encode() - fd = sock.makefile('rwb') - fd.write(request) - fd.flush() + request = 'GET /%s HTTP/1.0\r\nHost: localhost\r\n\r\n' % path + send_expect_close(sock, request.encode()) + fd = sock.makefile('rb') result = fd.readline() if result: # windows closes the socket before the data is flushed, @@ -1196,23 +1207,17 @@ class TestHttpd(_TestBase): sock = eventlet.connect(('localhost', self.port)) request = 'GET / HTTP/1.0\r\nHost: localhost\r\nLong: %s\r\n\r\n' % \ ('a' * 10000) - fd = sock.makefile('rwb') - fd.write(request.encode()) - fd.flush() + send_expect_close(sock, request.encode()) result = read_http(sock) self.assertEqual(result.status, 'HTTP/1.0 400 Header Line Too Long') - fd.close() def test_031_reject_large_headers(self): sock = eventlet.connect(('localhost', self.port)) headers = ('Name: %s\r\n' % ('a' * 7000,)) * 20 request = 'GET / HTTP/1.0\r\nHost: localhost\r\n%s\r\n\r\n' % headers - fd = sock.makefile('rwb') - fd.write(request.encode()) - fd.flush() + send_expect_close(sock, request.encode()) result = read_http(sock) self.assertEqual(result.status, 'HTTP/1.0 400 Headers Too Large') - fd.close() def test_032_wsgi_input_as_iterable(self): # https://bitbucket.org/eventlet/eventlet/issue/150