mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
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.
This commit is contained in:
@ -58,12 +58,19 @@ class OutputChecker(object):
|
|||||||
|
|
||||||
r = os.read(self._pipe_fd_r, 1024)
|
r = os.read(self._pipe_fd_r, 1024)
|
||||||
if not r:
|
if not r:
|
||||||
|
os.close(self._pipe_fd_r)
|
||||||
|
self._pipe_fd_r = -1
|
||||||
|
self._lines_sem.release()
|
||||||
return
|
return
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EWOULDBLOCK:
|
if e.errno == errno.EWOULDBLOCK:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# We get a bad file descriptor error when the outside closes the FD
|
# 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
|
return
|
||||||
|
|
||||||
l = r.split(b'\n')
|
l = r.split(b'\n')
|
||||||
@ -88,6 +95,13 @@ class OutputChecker(object):
|
|||||||
try:
|
try:
|
||||||
l = self._lines.pop(0)
|
l = self._lines.pop(0)
|
||||||
except IndexError:
|
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
|
# Check if should wake up
|
||||||
if not self._lines_sem.acquire(timeout = deadline - time.time()):
|
if not self._lines_sem.acquire(timeout = deadline - time.time()):
|
||||||
if failmsg:
|
if failmsg:
|
||||||
@ -121,6 +135,10 @@ class OutputChecker(object):
|
|||||||
try:
|
try:
|
||||||
l = self._lines.pop(0)
|
l = self._lines.pop(0)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
# EOF, so everything good
|
||||||
|
if self._pipe_fd_r == -1:
|
||||||
|
break
|
||||||
|
|
||||||
# Check if should wake up
|
# Check if should wake up
|
||||||
if not self._lines_sem.acquire(timeout = deadline - time.time()):
|
if not self._lines_sem.acquire(timeout = deadline - time.time()):
|
||||||
# Timed out, so everything is good
|
# Timed out, so everything is good
|
||||||
@ -159,7 +177,8 @@ class OutputChecker(object):
|
|||||||
|
|
||||||
fd = self._pipe_fd_r
|
fd = self._pipe_fd_r
|
||||||
self._pipe_fd_r = -1
|
self._pipe_fd_r = -1
|
||||||
os.close(fd)
|
if fd >= 0:
|
||||||
|
os.close(fd)
|
||||||
|
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
|
|
||||||
@ -172,9 +191,9 @@ class OutputChecker(object):
|
|||||||
self._pipe_fd_w = -1
|
self._pipe_fd_w = -1
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._pipe_fd_r > 0:
|
if self._pipe_fd_r >= 0:
|
||||||
os.close(self._pipe_fd_r)
|
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)
|
os.close(self._pipe_fd_w)
|
||||||
|
self._pipe_fd_w = -1
|
||||||
assert not self._thread.is_alive()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user