[gnome-settings-daemon/benzea/test-fixes: 5/5] tests/output_checker: Don't close FD from thread
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/benzea/test-fixes: 5/5] tests/output_checker: Don't close FD from thread
- Date: Thu, 10 Feb 2022 17:30:45 +0000 (UTC)
commit 01e9313e0e4e62d57663178291456347c147a40b
Author: Benjamin Berg <bberg redhat com>
Date: Thu Feb 10 18:01:18 2022 +0100
tests/output_checker: Don't close FD from thread
Otherwise there is a race condition that can cause the FD to be closed
twice. Avoid this by signalling EOF through a separate variable and
always closing the FD from the main thread.
tests/output_checker.py | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
---
diff --git a/tests/output_checker.py b/tests/output_checker.py
index 265e3234..df378cd5 100644
--- a/tests/output_checker.py
+++ b/tests/output_checker.py
@@ -31,6 +31,7 @@ class OutputChecker(object):
def __init__(self, out=sys.stdout):
self._output = out
self._pipe_fd_r, self._pipe_fd_w = os.pipe()
+ self._eof = False
self._partial_buf = b''
self._lines_sem = threading.Semaphore()
self._lines = []
@@ -58,8 +59,7 @@ 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._eof = True
self._lines_sem.release()
return
except OSError as e:
@@ -67,9 +67,6 @@ class OutputChecker(object):
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
@@ -96,7 +93,7 @@ class OutputChecker(object):
l = self._lines.pop(0)
except IndexError:
# EOF, throw error
- if self._pipe_fd_r == -1:
+ if self._eof:
if failmsg:
raise AssertionError("No further messages: " % failmsg)
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]