summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2021-07-23 13:49:14 +0200
committerBenjamin Berg <bberg@redhat.com>2021-07-23 13:50:52 +0200
commit9ae3c16f2dfbe55bd627e24f21efa95d3561d42e (patch)
tree28f64769ede2d5f7ae51bd9bb622f103f2c20610
parentf4995dcabe6178ea595dd670b2b564c1c522c06d (diff)
tests: Pull more OutputChecker fixes
While debugging the g-s-d testsuite a few more issues in the OutputChecker code came up. Pull in these fixes ensuring that EOF and the read side FD are handled correctly.
-rw-r--r--tests/output_checker.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/output_checker.py b/tests/output_checker.py
index 765da9c..265e323 100644
--- a/tests/output_checker.py
+++ b/tests/output_checker.py
@@ -58,12 +58,19 @@ class OutputChecker(object):
r = os.read(self._pipe_fd_r, 1024)
if not r:
+ os.close(self._pipe_fd_r)
+ self._pipe_fd_r = -1
+ self._lines_sem.release()
return
except OSError as e:
if e.errno == errno.EWOULDBLOCK:
continue
# We get a bad file descriptor error when the outside closes the FD
+ if self._pipe_fd_r >= 0:
+ os.close(self._pipe_fd_r)
+ self._pipe_fd_r = -1
+ self._lines_sem.release()
return
l = r.split(b'\n')
@@ -88,6 +95,13 @@ class OutputChecker(object):
try:
l = self._lines.pop(0)
except IndexError:
+ # EOF, throw error
+ if self._pipe_fd_r == -1:
+ if failmsg:
+ raise AssertionError("No further messages: " % failmsg)
+ else:
+ raise AssertionError('No client waiting for needle %s' % (str(needle_re)))
+
# Check if should wake up
if not self._lines_sem.acquire(timeout = deadline - time.time()):
if failmsg:
@@ -121,6 +135,10 @@ class OutputChecker(object):
try:
l = self._lines.pop(0)
except IndexError:
+ # EOF, so everything good
+ if self._pipe_fd_r == -1:
+ break
+
# Check if should wake up
if not self._lines_sem.acquire(timeout = deadline - time.time()):
# Timed out, so everything is good
@@ -159,7 +177,8 @@ class OutputChecker(object):
fd = self._pipe_fd_r
self._pipe_fd_r = -1
- os.close(fd)
+ if fd >= 0:
+ os.close(fd)
self._thread.join()
@@ -172,9 +191,9 @@ class OutputChecker(object):
self._pipe_fd_w = -1
def __del__(self):
- if self._pipe_fd_r > 0:
+ if self._pipe_fd_r >= 0:
os.close(self._pipe_fd_r)
- if self._pipe_fd_w > 0:
+ self._pipe_fd_r = -1
+ if self._pipe_fd_w >= 0:
os.close(self._pipe_fd_w)
-
- assert not self._thread.is_alive()
+ self._pipe_fd_w = -1