summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAndrew Yourtchenko <ayourtch@gmail.com>2019-11-05 19:38:08 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-11-18 13:28:35 +0000
commit93feaa2fffd04c8abe34c01513e1a84c95232253 (patch)
treebae2c308402e90f597e9d8bbe9f11b645303be1a /test
parent59aed0eed41e0b2441cb3f2929a3c0cd20ace4c5 (diff)
tests: make threads in punt tests join when finished
The 42693521f6046997133c8f63bcfc9d615d96f69d added the timeout to the child process join + print the name of the offending child process. Upon testing the issue furher, appeared the offenders were always the same - punt tests. The processes running them were stuck trying to acquire lock, even if all the user-accessible execution has finished. Some searching revealed that one needs to tread carefully when dealing with Thread and Multiprocessing at the same time. punt tests used threads but did not call thread.join. Somehow it worked in some cases but not the others. This fix makes the threads exit cleanly - which also makes the timeouts waiting for the process to join disappear. Type: test Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com> Change-Id: I05d99bb48a9987544bbfe45118755c09d7867aa0 Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com> (cherry picked from commit 3f8c87132d63c14f1ba90d7db6cf2a2aba0f8cb9)
Diffstat (limited to 'test')
-rw-r--r--test/test_punt.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/test/test_punt.py b/test/test_punt.py
index 0b4585a15c7..ec72e8cad9d 100644
--- a/test/test_punt.py
+++ b/test/test_punt.py
@@ -6,6 +6,9 @@ import os
import threading
import struct
import copy
+import fcntl
+import time
+
from struct import unpack, unpack_from
try:
@@ -43,17 +46,26 @@ class serverSocketThread(threading.Thread):
self.sockName = sockName
self.sock = None
self.rx_pkts = []
+ self.keep_running = True
def rx_packets(self):
# Wait for some packets on socket
- while True:
- data = self.sock.recv(65536)
-
- # punt socket metadata
- # packet_desc = data[0:8]
-
- # Ethernet
- self.rx_pkts.append(Ether(data[8:]))
+ while self.keep_running:
+ try:
+ data = self.sock.recv(65536)
+
+ # punt socket metadata
+ # packet_desc = data[0:8]
+
+ # Ethernet
+ self.rx_pkts.append(Ether(data[8:]))
+ except IOError as e:
+ if e.errno == 11:
+ # nothing to receive, sleep a little
+ time.sleep(0.1)
+ pass
+ else:
+ raise
def run(self):
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
@@ -63,12 +75,14 @@ class serverSocketThread(threading.Thread):
pass
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 65536)
+ fcntl.fcntl(self.sock, fcntl.F_SETFL, os.O_NONBLOCK)
self.sock.bind(self.sockName)
self.rx_packets()
def close(self):
self.sock.close()
+ self.keep_running = False
return self.rx_pkts
@@ -117,6 +131,7 @@ class TestPuntSocket(VppTestCase):
rx_pkts = []
for thread in self.sock_servers:
rx_pkts += thread.close()
+ thread.join()
return rx_pkts
def verify_port(self, pr, vpr):