diff options
| author | Jakub Stasiak <jakub@stasiak.at> | 2014-11-11 22:38:30 +0000 |
|---|---|---|
| committer | Jakub Stasiak <jakub@stasiak.at> | 2014-11-11 22:47:09 +0000 |
| commit | e843a8ace3c2f37d2e47fc0b4a4dabd126411750 (patch) | |
| tree | c37533d832dc6ff6532fb4fc9c433ba1aa63ef6f /tests/wsgi_test.py | |
| parent | 67cde41d03c0bccb12fd7d5f6d7e155d6da95e40 (diff) | |
| download | eventlet-python3-clean-clean.tar.gz | |
Python 3 compat; Improve WSGI, WS, threading and testspython3-clean-clean
This includes:
* patching more tests to pass
* removing few unit tests which I think are redundant
* repeating SSL socket reads in a loop to read all data (I suspect this is
related to the fact that writelines is used in the server code there and
Python 3 writelines calls write/send repeatedly while on Python 2 it
calls it once; on one hand there's no guarantee that single recv/read
will return all data sent by the server, on the other hand it's quite
suspicious that the number of required reads seems to be connected to
the number of sends on the other side of the connection)
* working through Python 2/Python 3 threading and thread differences; the
lock code I used is the simplest way I could make the tests pass but
will likely need to be modified in order to match the original
This commit includes 6bcb1dc and closes GH #153
Diffstat (limited to 'tests/wsgi_test.py')
| -rw-r--r-- | tests/wsgi_test.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index a966038..c58d78b 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -145,6 +145,17 @@ hello world """ +def recvall(socket_): + result = b'' + while True: + chunk = socket_.recv() + result += chunk + if chunk == b'': + break + + return result + + class ConnectionClosed(Exception): pass @@ -449,8 +460,8 @@ class TestHttpd(_TestBase): sock.write( b'POST /foo HTTP/1.1\r\nHost: localhost\r\n' b'Connection: close\r\nContent-length:3\r\n\r\nabc') - result = sock.read(8192) - self.assertEqual(result[-3:], b'abc') + result = recvall(sock) + assert result.endswith(b'abc') @tests.skip_if_no_ssl def test_013_empty_return(self): @@ -469,8 +480,8 @@ class TestHttpd(_TestBase): sock = eventlet.connect(('localhost', server_sock.getsockname()[1])) sock = eventlet.wrap_ssl(sock) sock.write(b'GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') - result = sock.read(8192) - self.assertEqual(result[-4:], b'\r\n\r\n') + result = recvall(sock) + assert result[-4:] == b'\r\n\r\n' def test_014_chunked_post(self): self.site.application = chunked_post @@ -964,9 +975,9 @@ class TestHttpd(_TestBase): try: client = ssl.wrap_socket(eventlet.connect(('localhost', port))) client.write(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n') - result = client.read() - assert result.startswith('HTTP'), result - assert result.endswith('hello world') + result = recvall(client) + assert result.startswith(b'HTTP'), result + assert result.endswith(b'hello world') except ImportError: pass # TODO(openssl): should test with OpenSSL greenthread.kill(g) |
