tests: Add a socket timeout

On FreeBSD a races seems to occur between the states socket connecting
and VPP accepting the connection and calling getpeername. The recv_fd
call here will fail with no fds before the VPP process has time to
handle the connection.

Introducing a socket timeout removes this failure on FreeBSD and allows
the test suite to run. Add a timeout on all platforms to try to avoid
this race everywhere.

Type: improvement
Change-Id: I96f77f924a9491222bc213b534cb17001d081f3f
Signed-off-by: Tom Jones <thj@freebsd.org>
diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py
index 8cbe737..aa9ff85 100755
--- a/src/vpp-api/python/vpp_papi/vpp_stats.py
+++ b/src/vpp-api/python/vpp_papi/vpp_stats.py
@@ -136,6 +136,12 @@
         if self.connected:
             return
         sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+
+        # Our connect races the corresponding recv_fds call in VPP, if we beat
+        # VPP then we will try (unsuccessfully) to receive file descriptors and
+        # will have gone away before VPP can respond to our connect.  A short
+        # timeout here stops this error occurring.
+        sock.settimeout(1)
         sock.connect(self.socketname)
 
         mfd = recv_fd(sock)