diff options
author | Benjamin Berg <bberg@redhat.com> | 2022-02-10 18:01:18 +0100 |
---|---|---|
committer | Benjamin Berg <benjamin@sipsolutions.net> | 2022-02-10 18:30:27 +0000 |
commit | 6461a0f8556bafbf58c8a2ff8b3fe83b7d0df2b7 (patch) | |
tree | 81849db0c0c9362a7d0aa353361d48407d48676f /tests | |
parent | ca1e78efd7d1d03b212186bdc92bba96227c1eac (diff) | |
download | gnome-settings-daemon-6461a0f8556bafbf58c8a2ff8b3fe83b7d0df2b7.tar.gz |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/output_checker.py | 9 |
1 files 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: |