From 23dbc512c2d1839deca0efdd1b02769e8d4fef71 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Mon, 25 Jul 2016 09:54:39 -0700 Subject: [PATCH] Fix two flakey tests --- tests/child_processes_test.py | 7 +++---- tests/cli_test.py | 10 +++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/child_processes_test.py b/tests/child_processes_test.py index 35f0aeb..7a8d9e7 100644 --- a/tests/child_processes_test.py +++ b/tests/child_processes_test.py @@ -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 ) diff --git a/tests/cli_test.py b/tests/cli_test.py index 19ac466..9bde4a8 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -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