diff --git a/test/reaping/stage_1.py b/test/reaping/stage_1.py index de39b66..10d87ab 100755 --- a/test/reaping/stage_1.py +++ b/test/reaping/stage_1.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from __future__ import print_function import os +import sys import subprocess import time @@ -29,6 +30,14 @@ def main(): break time.sleep(1) + # Now, check if there are any zombies + for process in psutil.process_iter(): + if process.name() == "sleep": + print("At least one 'sleep' process was still alive or not reaped! (pid{0})".format(process.pid)) + sys.exit(1) + + sys.exit(0) + if __name__ == "__main__": main() diff --git a/test/run_inner_tests.py b/test/run_inner_tests.py index 5e25a6b..0828853 100755 --- a/test/run_inner_tests.py +++ b/test/run_inner_tests.py @@ -13,20 +13,44 @@ def main(): proxy = os.path.join(src, "test", "subreaper-proxy.py") tini = os.path.join(build, "tini") - # Run the reaping test - print "Running reaping test" - p = subprocess.Popen([proxy, tini, "--", os.path.join(src, "test", "reaping", "stage_1.py")]) - ret = p.wait() - assert ret == 0, "Reaping test failed!" + for target, env in [ + ([proxy, tini, "--"], {}), + ([tini, "-s", "--"], {}), + ([tini, "--"], {"TINI_SUBREAPER": ""}), + ]: - # Run the signals test - for signame in "SIGINT", "SIGTERM": - print "running signal test for: {0}".format(signame) - p = subprocess.Popen([proxy, tini, "--", os.path.join(src, "test", "signals", "test.py")]) - sig = getattr(signal, signame) - p.send_signal(sig) + # Run the reaping test + print "Running reaping test ({0} with env {1})".format(" ".join(target), env) + p = subprocess.Popen(target + [os.path.join(src, "test", "reaping", "stage_1.py")], + env=dict(os.environ, **env), + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + out, err = p.communicate() + assert "zombie reaping won't work" not in err, "Warning message was output!" ret = p.wait() - assert ret == - sig, "Signals test failed!" + assert ret == 0, "Reaping test failed!" + + + # Run the signals test + for signame in "SIGINT", "SIGTERM": + print "running signal test for: {0} ({1} with env {2})".format(signame, " ".join(target), env) + p = subprocess.Popen(target + [os.path.join(src, "test", "signals", "test.py")], env=dict(os.environ, **env)) + sig = getattr(signal, signame) + p.send_signal(sig) + ret = p.wait() + assert ret == - sig, "Signals test failed!" + + # Run failing test + print "Running failing test" + p = subprocess.Popen([tini, "--", os.path.join(src, "test", "reaping", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + assert "zombie reaping won't work" in err, "No warning message was output!" + ret = p.wait() + assert ret == 1, "Reaping test succeeded (it should have failed)!" + + print "---------------------------" + print "All done, tests as expected" + print "---------------------------" if __name__ == "__main__":