Handle socket failures while testing latency
This commit is contained in:
parent
ced2890261
commit
5d0c62faec
42
speedtest.py
42
speedtest.py
|
@ -1517,21 +1517,33 @@ class Speedtest(object):
|
||||||
results = {}
|
results = {}
|
||||||
for server in servers:
|
for server in servers:
|
||||||
cum = []
|
cum = []
|
||||||
sock = connection_factory(
|
try:
|
||||||
server['host'],
|
sock = connection_factory(
|
||||||
timeout=self._timeout,
|
server['host'],
|
||||||
source_address=source_address
|
timeout=self._timeout,
|
||||||
)
|
source_address=source_address
|
||||||
|
)
|
||||||
sock.sendall('HI\n'.encode())
|
sock.sendall('HI\n'.encode())
|
||||||
sock.recv(1024)
|
sock.recv(1024)
|
||||||
|
except socket.error:
|
||||||
|
e = get_exception()
|
||||||
|
printer('ERROR: %r' % e, debug=True)
|
||||||
|
cum.append(3600 * 3)
|
||||||
|
continue
|
||||||
|
|
||||||
for _ in range(0, 3):
|
for _ in range(0, 3):
|
||||||
start = timeit.default_timer()
|
start = timeit.default_timer()
|
||||||
sock.sendall(
|
try:
|
||||||
('PING %d\n' % (int(timeit.time.time()) * 1000,)).encode()
|
sock.sendall(
|
||||||
)
|
('PING %d\n' %
|
||||||
resp = sock.recv(1024)
|
(int(timeit.time.time()) * 1000,)).encode()
|
||||||
|
)
|
||||||
|
resp = sock.recv(1024)
|
||||||
|
except socket.errror:
|
||||||
|
e = get_exception()
|
||||||
|
printer('ERROR: %r' % e, debug=True)
|
||||||
|
cum.append(3600)
|
||||||
|
continue
|
||||||
total = (timeit.default_timer() - start)
|
total = (timeit.default_timer() - start)
|
||||||
if resp.startswith('PONG '.encode()):
|
if resp.startswith('PONG '.encode()):
|
||||||
cum.append(total)
|
cum.append(total)
|
||||||
|
@ -1560,8 +1572,12 @@ class Speedtest(object):
|
||||||
try:
|
try:
|
||||||
fastest = sorted(results.keys())[0]
|
fastest = sorted(results.keys())[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
if self._use_socket:
|
||||||
|
extra = ' Try the HTTP based tests by removing --socket.'
|
||||||
|
else:
|
||||||
|
extra = ''
|
||||||
raise SpeedtestBestServerFailure('Unable to connect to servers to '
|
raise SpeedtestBestServerFailure('Unable to connect to servers to '
|
||||||
'test latency.')
|
'test latency.%s' % extra)
|
||||||
best = results[fastest]
|
best = results[fastest]
|
||||||
best['latency'] = fastest
|
best['latency'] = fastest
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue