Tests: increase default "read_timeout" value to 60s.

This change is necessary to avoid errors on slow hosts.

Also slightly reworked argument passing to the recvall() function.
This commit is contained in:
Andrei Zeliankou
2020-03-23 19:18:26 +00:00
parent ac9ca6d75c
commit 48ad88ee72
2 changed files with 16 additions and 15 deletions

View File

@@ -52,7 +52,7 @@ class TestApplicationWebsocket(TestApplicationProto):
) )
resp = '' resp = ''
while select.select([sock], [], [], 30)[0]: while select.select([sock], [], [], 60)[0]:
resp += sock.recv(4096).decode() resp += sock.recv(4096).decode()
if ( if (
@@ -70,7 +70,7 @@ class TestApplicationWebsocket(TestApplicationProto):
def serialize_close(self, code=1000, reason=''): def serialize_close(self, code=1000, reason=''):
return struct.pack('!H', code) + reason.encode('utf-8') return struct.pack('!H', code) + reason.encode('utf-8')
def frame_read(self, sock, read_timeout=30): def frame_read(self, sock, read_timeout=60):
def recv_bytes(sock, bytes): def recv_bytes(sock, bytes):
data = b'' data = b''
while select.select([sock], [], [], read_timeout)[0]: while select.select([sock], [], [], read_timeout)[0]:

View File

@@ -17,11 +17,6 @@ class TestHTTP(TestUnit):
port = 7080 if 'port' not in kwargs else kwargs['port'] port = 7080 if 'port' not in kwargs else kwargs['port']
url = '/' if 'url' not in kwargs else kwargs['url'] url = '/' if 'url' not in kwargs else kwargs['url']
http = 'HTTP/1.0' if 'http_10' in kwargs else 'HTTP/1.1' http = 'HTTP/1.0' if 'http_10' in kwargs else 'HTTP/1.1'
read_buffer_size = (
4096
if 'read_buffer_size' not in kwargs
else kwargs['read_buffer_size']
)
headers = ( headers = (
{'Host': 'localhost', 'Connection': 'close'} {'Host': 'localhost', 'Connection': 'close'}
@@ -101,12 +96,15 @@ class TestHTTP(TestUnit):
resp = '' resp = ''
if 'no_recv' not in kwargs: if 'no_recv' not in kwargs:
read_timeout = ( recvall_kwargs = {}
30 if 'read_timeout' not in kwargs else kwargs['read_timeout']
) if 'read_timeout' in kwargs:
resp = self.recvall( recvall_kwargs['read_timeout'] = kwargs['read_timeout']
sock, read_timeout=read_timeout, buff_size=read_buffer_size
).decode(encoding) if 'read_buffer_size' in kwargs:
recvall_kwargs['buff_size'] = kwargs['read_buffer_size']
resp = self.recvall(sock, **recvall_kwargs).decode(encoding)
self.log_in(resp) self.log_in(resp)
@@ -174,9 +172,12 @@ class TestHTTP(TestUnit):
def put(self, **kwargs): def put(self, **kwargs):
return self.http('PUT', **kwargs) return self.http('PUT', **kwargs)
def recvall(self, sock, read_timeout=30, buff_size=4096): def recvall(self, sock, **kwargs):
timeout = 60 if 'read_timeout' not in kwargs else kwargs['read_timeout']
buff_size = 4096 if 'buff_size' not in kwargs else kwargs['buff_size']
data = b'' data = b''
while select.select([sock], [], [], read_timeout)[0]: while select.select([sock], [], [], timeout)[0]:
try: try:
part = sock.recv(buff_size) part = sock.recv(buff_size)
except: except: