Commit 2895d0bd authored by Denis Bilenko's avatar Denis Bilenko

add server_implements_pipeline option to test__pywsgi.py which disables tests...

add server_implements_pipeline option to test__pywsgi.py which disables tests that depend on pipelining working in test__wsgi.py
parent 0d840cf9
...@@ -39,6 +39,7 @@ from gevent import socket ...@@ -39,6 +39,7 @@ from gevent import socket
CONTENT_LENGTH = 'Content-Length' CONTENT_LENGTH = 'Content-Length'
CONN_ABORTED_ERRORS = [] CONN_ABORTED_ERRORS = []
server_implements_chunked = True server_implements_chunked = True
server_implements_pipeline = True
server_implements_100continue = True server_implements_100continue = True
DEBUG = '-v' in sys.argv DEBUG = '-v' in sys.argv
...@@ -238,7 +239,9 @@ class CommonTests(TestCase): ...@@ -238,7 +239,9 @@ class CommonTests(TestCase):
def test_basic(self): def test_basic(self):
fd = self.connect().makefile(bufsize=1) fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd, body='hello world') response = read_http(fd, body='hello world')
if response.headers.get('Connection') == 'close' and not server_implements_pipeline:
return
fd.write('GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd, code=404, reason='Not Found', body='not found') read_http(fd, code=404, reason='Not Found', body='not found')
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
...@@ -246,6 +249,8 @@ class CommonTests(TestCase): ...@@ -246,6 +249,8 @@ class CommonTests(TestCase):
fd.close() fd.close()
def test_pipeline(self): def test_pipeline(self):
if not server_implements_pipeline:
return
fd = self.connect().makefile(bufsize=1) fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n' + 'GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n' + 'GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd, body='hello world') read_http(fd, body='hello world')
...@@ -264,7 +269,9 @@ class CommonTests(TestCase): ...@@ -264,7 +269,9 @@ class CommonTests(TestCase):
def test_connection_close(self): def test_connection_close(self):
fd = self.connect().makefile(bufsize=1) fd = self.connect().makefile(bufsize=1)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
read_http(fd) response = read_http(fd)
if response.headers.get('Connection') == 'close' and not server_implements_pipeline:
return
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
read_http(fd) read_http(fd)
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
...@@ -311,6 +318,9 @@ class TestNoChunks(CommonTests): ...@@ -311,6 +318,9 @@ class TestNoChunks(CommonTests):
assert response.chunks is None, response.chunks assert response.chunks is None, response.chunks
response.assertHeader('Content-Length', '11') response.assertHeader('Content-Length', '11')
if not server_implements_pipeline:
fd = self.connect().makefile(bufsize=1)
fd.write('GET /not-found HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.write('GET /not-found HTTP/1.1\r\nHost: localhost\r\n\r\n')
response = read_http(fd, code=404, reason='Not Found', body='not found') response = read_http(fd, code=404, reason='Not Found', body='not found')
assert response.chunks is None, response.chunks assert response.chunks is None, response.chunks
...@@ -718,6 +728,15 @@ class ChunkedInputTests(TestCase): ...@@ -718,6 +728,15 @@ class ChunkedInputTests(TestCase):
fd.write("GET /ping HTTP/1.1\r\n\r\n") fd.write("GET /ping HTTP/1.1\r\n\r\n")
read_http(fd, body="pong") read_http(fd, body="pong")
def ping_if_possible(self, fd):
try:
self.ping(fd)
except ConnectionClosed:
if server_implements_pipeline:
raise
fd = self.connect().makefile(bufsize=1)
self.ping(fd)
def test_short_read_with_content_length(self): def test_short_read_with_content_length(self):
body = self.body() body = self.body()
req = "POST /short-read HTTP/1.1\r\ntransfer-encoding: Chunked\r\nContent-Length:1000\r\n\r\n" + body req = "POST /short-read HTTP/1.1\r\ntransfer-encoding: Chunked\r\nContent-Length:1000\r\n\r\n" + body
...@@ -726,7 +745,7 @@ class ChunkedInputTests(TestCase): ...@@ -726,7 +745,7 @@ class ChunkedInputTests(TestCase):
fd.write(req) fd.write(req)
read_http(fd, body="this is ch") read_http(fd, body="this is ch")
self.ping(fd) self.ping_if_possible(fd)
def test_short_read_with_zero_content_length(self): def test_short_read_with_zero_content_length(self):
body = self.body() body = self.body()
...@@ -737,7 +756,7 @@ class ChunkedInputTests(TestCase): ...@@ -737,7 +756,7 @@ class ChunkedInputTests(TestCase):
fd.write(req) fd.write(req)
read_http(fd, body="this is ch") read_http(fd, body="this is ch")
self.ping(fd) self.ping_if_possible(fd)
def test_short_read(self): def test_short_read(self):
body = self.body() body = self.body()
...@@ -747,7 +766,7 @@ class ChunkedInputTests(TestCase): ...@@ -747,7 +766,7 @@ class ChunkedInputTests(TestCase):
fd.write(req) fd.write(req)
read_http(fd, body="this is ch") read_http(fd, body="this is ch")
self.ping(fd) self.ping_if_possible(fd)
def test_dirt(self): def test_dirt(self):
body = self.body(dirt="; here is dirt\0bla") body = self.body(dirt="; here is dirt\0bla")
...@@ -764,7 +783,7 @@ class ChunkedInputTests(TestCase): ...@@ -764,7 +783,7 @@ class ChunkedInputTests(TestCase):
return return
raise raise
self.ping(fd) self.ping_if_possible(fd)
def test_chunked_readline(self): def test_chunked_readline(self):
body = self.body() body = self.body()
......
...@@ -5,6 +5,7 @@ from test__pywsgi import * ...@@ -5,6 +5,7 @@ from test__pywsgi import *
del TestHttps del TestHttps
test__pywsgi.server_implements_chunked = False test__pywsgi.server_implements_chunked = False
test__pywsgi.server_implements_pipeline = False
test__pywsgi.server_implements_100continue = False test__pywsgi.server_implements_100continue = False
TestCase.get_wsgi_module = lambda *args: wsgi TestCase.get_wsgi_module = lambda *args: wsgi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment