speed up python tests more than 10 fold by sleeping less
The VTYInteract tests gave a constant sleep(1) grace period for the process to startup. This caused the test to take minutes for no reason at all. Add code to VTYInteract._connect_socket() 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. When TCP socket debugging is switched on, also print how many connection tries it took to connect the VTY socket. Note that the openbsc python tests also add some sleep()s that also need to be removed to benefit from this. Change-Id: Icc337f52a93d5fe31fc4ff235ccaf4e0fe75fa39
This commit is contained in:
parent
4e64b8821d
commit
abd4b7d705
|
@ -20,6 +20,7 @@ import re
|
|||
import socket
|
||||
import sys, subprocess
|
||||
import os
|
||||
import time
|
||||
|
||||
"""VTYInteract: interact with an osmocom vty
|
||||
|
||||
|
@ -71,13 +72,29 @@ class VTYInteract(object):
|
|||
def _connect_socket(self):
|
||||
if self.socket is not None:
|
||||
return
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.socket.setblocking(1)
|
||||
self.socket.connect((self.host, self.port))
|
||||
retries = 30
|
||||
took = 0
|
||||
while True:
|
||||
took += 1
|
||||
try:
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.socket.setblocking(1)
|
||||
self.socket.connect((self.host, self.port))
|
||||
except IOError:
|
||||
retries -= 1
|
||||
if retries <= 0:
|
||||
raise
|
||||
# possibly the binary hasn't launched yet
|
||||
if debug_tcp_sockets:
|
||||
print "Connecting socket failed, retrying..."
|
||||
time.sleep(.1)
|
||||
continue
|
||||
break
|
||||
|
||||
if debug_tcp_sockets:
|
||||
VTYInteract.all_sockets.append(self.socket)
|
||||
print "Socket: connected to %s:%d %r (%d sockets open)" % (
|
||||
self.host, self.port, self.socket,
|
||||
print "Socket: in %d tries, connected to %s:%d %r (%d sockets open)" % (
|
||||
took, self.host, self.port, self.socket,
|
||||
len(VTYInteract.all_sockets))
|
||||
self.socket.recv(4096)
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ def dump_configs(apps, configs):
|
|||
print >> sys.stderr, "Skipping app %s" % appname
|
||||
failures += 1
|
||||
else:
|
||||
time.sleep(1)
|
||||
try:
|
||||
dump_doc(app[2], app[0], 'doc/%s_vty_reference.xml' % appname)
|
||||
successes += 1
|
||||
|
|
|
@ -55,7 +55,6 @@ def test_config_atest(app_desc, config, run_test, verbose=True):
|
|||
print "Verifying %s, test %s" % (' '.join(cmd), run_test.__name__)
|
||||
|
||||
proc = osmoutil.popen_devnull(cmd)
|
||||
time.sleep(1)
|
||||
end = app_desc[2]
|
||||
port = app_desc[0]
|
||||
vty = obscvty.VTYInteract(end, "127.0.0.1", port)
|
||||
|
|
|
@ -41,7 +41,6 @@ class TestVTY(unittest.TestCase):
|
|||
except OSError:
|
||||
print >> sys.stderr, "Current directory: %s" % os.getcwd()
|
||||
print >> sys.stderr, "Consider setting -b"
|
||||
time.sleep(1)
|
||||
|
||||
appstring = osmoappdesc.vty_app[2]
|
||||
appport = osmoappdesc.vty_app[0]
|
||||
|
|
Loading…
Reference in New Issue