Tests: read_timeout option introduced.
Also, increased default select() timeout from 1s to 5s.
This commit is contained in:
@@ -226,7 +226,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
|
|||||||
(resp, sock) = self.get(headers={
|
(resp, sock) = self.get(headers={
|
||||||
'Host': 'localhost',
|
'Host': 'localhost',
|
||||||
'Connection': 'keep-alive'
|
'Connection': 'keep-alive'
|
||||||
}, start=True)
|
}, start=True, read_timeout=1)
|
||||||
self.assertEqual(len(self.pids_for_process()), 1,
|
self.assertEqual(len(self.pids_for_process()), 1,
|
||||||
'keepalive connection 1')
|
'keepalive connection 1')
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class TestUnitSettings(unit.TestUnitApplicationPython):
|
|||||||
self.conf({'http': { 'header_read_timeout': 2 }}, 'settings')
|
self.conf({'http': { 'header_read_timeout': 2 }}, 'settings')
|
||||||
|
|
||||||
(resp, sock) = self.http(b"""GET / HTTP/1.1
|
(resp, sock) = self.http(b"""GET / HTTP/1.1
|
||||||
""", start=True, raw=True)
|
""", start=True, read_timeout=1, raw=True)
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
@@ -31,17 +31,17 @@ Connection: close
|
|||||||
self.conf({'http': { 'header_read_timeout': 4 }}, 'settings')
|
self.conf({'http': { 'header_read_timeout': 4 }}, 'settings')
|
||||||
|
|
||||||
(resp, sock) = self.http(b"""GET / HTTP/1.1
|
(resp, sock) = self.http(b"""GET / HTTP/1.1
|
||||||
""", start=True, raw=True, no_recv=True)
|
""", start=True, read_timeout=1, raw=True, no_recv=True)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
(resp, sock) = self.http(b"""Host: localhost
|
(resp, sock) = self.http(b"""Host: localhost
|
||||||
""", start=True, sock=sock, raw=True, no_recv=True)
|
""", start=True, sock=sock, read_timeout=1, raw=True, no_recv=True)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
(resp, sock) = self.http(b"""X-Blah: blah
|
(resp, sock) = self.http(b"""X-Blah: blah
|
||||||
""", start=True, sock=sock, raw=True)
|
""", start=True, sock=sock, read_timeout=1, raw=True)
|
||||||
|
|
||||||
if len(resp) != 0:
|
if len(resp) != 0:
|
||||||
sock.close()
|
sock.close()
|
||||||
@@ -66,7 +66,7 @@ Host: localhost
|
|||||||
Content-Length: 10
|
Content-Length: 10
|
||||||
Connection: close
|
Connection: close
|
||||||
|
|
||||||
""", start=True, raw_resp=True, raw=True)
|
""", start=True, raw_resp=True, read_timeout=1, raw=True)
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
@@ -84,15 +84,17 @@ Host: localhost
|
|||||||
Content-Length: 10
|
Content-Length: 10
|
||||||
Connection: close
|
Connection: close
|
||||||
|
|
||||||
""", start=True, raw=True)
|
""", start=True, read_timeout=1, raw=True)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
(resp, sock) = self.http(b"""012""", start=True, sock=sock, raw=True)
|
(resp, sock) = self.http(b"""012""", start=True, sock=sock,
|
||||||
|
read_timeout=1, raw=True)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
(resp, sock) = self.http(b"""345""", start=True, sock=sock, raw=True)
|
(resp, sock) = self.http(b"""345""", start=True, sock=sock,
|
||||||
|
read_timeout=1, raw=True)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
@@ -143,7 +145,7 @@ Connection: close
|
|||||||
(resp, sock) = self.get(headers={
|
(resp, sock) = self.get(headers={
|
||||||
'Host': 'localhost',
|
'Host': 'localhost',
|
||||||
'Connection': 'keep-alive'
|
'Connection': 'keep-alive'
|
||||||
}, start=True)
|
}, start=True, read_timeout=1)
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
|
|||||||
@@ -357,7 +357,8 @@ class TestUnitHTTP(TestUnit):
|
|||||||
|
|
||||||
if 'no_recv' not in kwargs:
|
if 'no_recv' not in kwargs:
|
||||||
enc = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding']
|
enc = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding']
|
||||||
resp = self.recvall(sock).decode(enc)
|
read_timeout = 5 if 'read_timeout' not in kwargs else kwargs['read_timeout']
|
||||||
|
resp = self.recvall(sock, read_timeout=read_timeout).decode(enc)
|
||||||
|
|
||||||
if TestUnit.detailed:
|
if TestUnit.detailed:
|
||||||
print('<<<', resp.encode('utf-8'), sep='\n')
|
print('<<<', resp.encode('utf-8'), sep='\n')
|
||||||
@@ -383,9 +384,9 @@ class TestUnitHTTP(TestUnit):
|
|||||||
def put(self, **kwargs):
|
def put(self, **kwargs):
|
||||||
return self.http('PUT', **kwargs)
|
return self.http('PUT', **kwargs)
|
||||||
|
|
||||||
def recvall(self, sock, buff_size=4096):
|
def recvall(self, sock, read_timeout=5, buff_size=4096):
|
||||||
data = b''
|
data = b''
|
||||||
while select.select([sock], [], [], 1)[0]:
|
while select.select([sock], [], [], read_timeout)[0]:
|
||||||
try:
|
try:
|
||||||
part = sock.recv(buff_size)
|
part = sock.recv(buff_size)
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user