Catch scenario where no servers could be connected to for latency tests

This commit is contained in:
Matt Martz 2016-09-26 11:07:02 -05:00
parent 2be4d0a5e7
commit b075152e3e
1 changed files with 9 additions and 1 deletions

View File

@ -262,6 +262,10 @@ class SpeedtestUploadTimeout(SpeedtestException):
"""
class SpeedtestBestServerFailure(SpeedtestException):
"""Unable to determine best server"""
def bound_socket(*args, **kwargs):
"""Bind socket to a specified source IP address"""
@ -912,7 +916,11 @@ class Speedtest(object):
avg = round((sum(cum) / 6) * 1000.0, 3)
results[avg] = server
fastest = sorted(results.keys())[0]
try:
fastest = sorted(results.keys())[0]
except IndexError:
raise SpeedtestBestServerFailure('Unable to connect to servers to '
'test latency.')
best = results[fastest]
best['latency'] = fastest