diff options
| author | Johannes Erdfelt <johannes@erdfelt.com> | 2014-12-19 14:54:04 -0800 |
|---|---|---|
| committer | Sergey Shepelev <temotor@gmail.com> | 2014-12-22 21:34:44 +0300 |
| commit | 7b05b3a1ee454bdff42509febf54b3c12979f22c (patch) | |
| tree | 3f09b697949d9e5772e7f0214c8254a69dad89b4 | |
| parent | 99a5869aa0ff889076793b28d99b28d6063b412b (diff) | |
| download | eventlet-issue178.tar.gz | |
Handle EPIPE errors during tests when remote end closes connectionissue178
Closes #178
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.
| -rw-r--r-- | tests/wsgi_test.py | 29 |
1 files changed, 17 insertions, 12 deletions
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 |
