ctrl_test_runner: speed up more than 10 fold by sleeping less

Similar to a recent patch in osmo-python-tests for VTY based tests, but this is
for the Ctrl tests.

The TestCtrlBase tests gave a constant sleep(2) grace period for the process to
startup. This causes tests to take minutes for no reason at all.

Add code to TestCtrlBase to try and connect right away, retrying up to three
seconds in .1 second intervals. This flies through most tests without any
sleep() at all.

Change-Id: I06569767153838bd9cd3edac001df5f6c567874c
This commit is contained in:
Neels Hofmeyr 2017-02-27 02:01:37 +01:00 committed by Harald Welte
parent 534034580c
commit acc6e8323a
1 changed files with 13 additions and 3 deletions

View File

@ -86,9 +86,19 @@ class TestCtrlBase(unittest.TestCase):
if verbose:
print "Connecting to host %s:%i" % (host, port)
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.setblocking(1)
sck.connect((host, port))
retries = 30
while True:
try:
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.setblocking(1)
sck.connect((host, port))
except IOError:
retries -= 1
if retries <= 0:
raise
time.sleep(.1)
continue
break
self.sock = sck
return sck