mirror of https://github.com/krallin/tini.git
Add tests for subreaping (and subreaping failures)
This commit is contained in:
parent
e1b463cdf5
commit
98e4449b36
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -29,6 +30,14 @@ def main():
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -13,20 +13,44 @@ def main():
|
||||||
proxy = os.path.join(src, "test", "subreaper-proxy.py")
|
proxy = os.path.join(src, "test", "subreaper-proxy.py")
|
||||||
tini = os.path.join(build, "tini")
|
tini = os.path.join(build, "tini")
|
||||||
|
|
||||||
# Run the reaping test
|
for target, env in [
|
||||||
print "Running reaping test"
|
([proxy, tini, "--"], {}),
|
||||||
p = subprocess.Popen([proxy, tini, "--", os.path.join(src, "test", "reaping", "stage_1.py")])
|
([tini, "-s", "--"], {}),
|
||||||
ret = p.wait()
|
([tini, "--"], {"TINI_SUBREAPER": ""}),
|
||||||
assert ret == 0, "Reaping test failed!"
|
]:
|
||||||
|
|
||||||
# Run the signals test
|
# Run the reaping test
|
||||||
for signame in "SIGINT", "SIGTERM":
|
print "Running reaping test ({0} with env {1})".format(" ".join(target), env)
|
||||||
print "running signal test for: {0}".format(signame)
|
p = subprocess.Popen(target + [os.path.join(src, "test", "reaping", "stage_1.py")],
|
||||||
p = subprocess.Popen([proxy, tini, "--", os.path.join(src, "test", "signals", "test.py")])
|
env=dict(os.environ, **env),
|
||||||
sig = getattr(signal, signame)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
p.send_signal(sig)
|
|
||||||
|
out, err = p.communicate()
|
||||||
|
assert "zombie reaping won't work" not in err, "Warning message was output!"
|
||||||
ret = p.wait()
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue