Fix two flakey tests

This commit is contained in:
Chris Kuehl 2016-07-25 09:54:39 -07:00
parent 62ca2aaace
commit 23dbc512c2
2 changed files with 10 additions and 7 deletions

View file

@ -91,8 +91,7 @@ def spawn_process_which_dies_with_children():
# read a line from print_signals, figure out its pid
line = proc.stdout.readline()
match = re.match(b'ready \(pid: ([0-9]+)\)\n', line)
assert match, 'print_signals should print "ready" and its pid, not ' + \
str(line)
assert match, line
child_pid = int(match.group(1))
# at this point, the shell and dumb-init have both exited, but
@ -139,9 +138,9 @@ def test_processes_dont_receive_term_on_exit_if_no_setsid():
def test_fails_nonzero_with_bad_exec(args):
"""If dumb-init can't exec as requested, it should exit nonzero."""
proc = Popen(('dumb-init',) + args, stderr=PIPE)
proc.wait()
_, stderr = proc.communicate()
assert proc.returncode != 0
assert (
b'[dumb-init] /doesnotexist: No such file or directory\n'
in proc.stderr
in stderr
)

View file

@ -82,16 +82,20 @@ def test_verbose(flag):
stdout, stderr = proc.communicate()
assert proc.returncode == 0
assert stdout == b'oh, hi\n'
assert re.match(
# child/parent race to print output after the fork(), can't guarantee exact order
assert re.search(b'(^|\n)\[dumb-init\] setsid complete\.\n', stderr), stderr # child
assert re.search( # parent
(
b'^\[dumb-init\] Child spawned with PID [0-9]+\.\n'
b'\[dumb-init\] setsid complete\.\n'
b'(^|\n)\[dumb-init\] Child spawned with PID [0-9]+\.\n'
b'.*' # child might print here
b'\[dumb-init\] Received signal 17\.\n'
b'\[dumb-init\] A child with PID [0-9]+ exited with exit status 0.\n'
b'\[dumb-init\] Forwarded signal 15 to children\.\n'
b'\[dumb-init\] Child exited with status 0\. Goodbye\.\n$'
),
stderr,
re.DOTALL,
), stderr