aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-27 01:03:44 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-03-06 15:31:08 +0100
commitabd4b7d7057bf4f33e9720c12853348562720c38 (patch)
tree806156eeec51a649d72477d7c1b3765892ca16c5
parent4e64b8821d73b29edab2e0a945ba3c05587cfd3a (diff)
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
-rwxr-xr-xosmopy/obscvty.py27
-rw-r--r--osmopy/osmodumpdoc.py1
-rw-r--r--osmopy/osmotestconfig.py1
-rw-r--r--osmopy/osmotestvty.py1
4 files changed, 22 insertions, 8 deletions
diff --git a/osmopy/obscvty.py b/osmopy/obscvty.py
index 857d75b..f1f1c59 100755
--- a/osmopy/obscvty.py
+++ b/osmopy/obscvty.py
@@ -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)
diff --git a/osmopy/osmodumpdoc.py b/osmopy/osmodumpdoc.py
index d9d52b5..0ff1f6b 100644
--- a/osmopy/osmodumpdoc.py
+++ b/osmopy/osmodumpdoc.py
@@ -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
diff --git a/osmopy/osmotestconfig.py b/osmopy/osmotestconfig.py
index 0d2b2d9..7b8ad66 100644
--- a/osmopy/osmotestconfig.py
+++ b/osmopy/osmotestconfig.py
@@ -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)
diff --git a/osmopy/osmotestvty.py b/osmopy/osmotestvty.py
index 9f8dd0a..e513c05 100644
--- a/osmopy/osmotestvty.py
+++ b/osmopy/osmotestvty.py
@@ -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]