diff options
author | Dave Wallace <dwallacelf@gmail.com> | 2021-05-07 21:40:54 -0400 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2021-05-08 02:49:06 +0000 |
commit | c44402f7b54d3290e7d1605e8e855f859ffe5331 (patch) | |
tree | 615664ff7d5f7b45da558847bdfe028354460a38 /test/test_punt.py | |
parent | 7508f0a7ea325b5c65f516acaa4ccd074a122af3 (diff) |
tests: fix another race condition in punt tests
- Don't close the socket and don't stop receiving
until after draining the existing data in the
socket.
Type: fix
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Change-Id: I38dfff4d6273eeddb5196f5cf2a60b580e1c93e6
Diffstat (limited to 'test/test_punt.py')
-rwxr-xr-x | test/test_punt.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/test/test_punt.py b/test/test_punt.py index bc2196eee1f..3471a3f7dd5 100755 --- a/test/test_punt.py +++ b/test/test_punt.py @@ -46,11 +46,11 @@ class serverSocketThread(threading.Thread): self.sockName = sockName self.sock = None self.rx_pkts = [] - self.keep_running = True + self.stop_running = False def rx_packets(self): # Wait for some packets on socket - while self.keep_running: + while True: try: data = self.sock.recv(65536) @@ -61,7 +61,9 @@ class serverSocketThread(threading.Thread): self.rx_pkts.append(Ether(data[8:])) except IOError as e: if e.errno == 11: - # nothing to receive, sleep a little + # nothing to receive, stop running or sleep a little + if self.stop_running: + break time.sleep(0.1) pass else: @@ -81,9 +83,9 @@ class serverSocketThread(threading.Thread): self.rx_packets() def close(self): - self.sock.close() - self.keep_running = False + self.stop_running = True threading.Thread.join(self) + self.sock.close() return self.rx_pkts |