2016-03-12 00:42:00 +03:00
|
|
|
import signal
|
2016-08-26 23:22:55 +03:00
|
|
|
import sys
|
2015-09-12 01:57:22 +03:00
|
|
|
from subprocess import Popen
|
|
|
|
|
2016-03-12 00:42:00 +03:00
|
|
|
import pytest
|
2015-09-12 01:57:22 +03:00
|
|
|
|
2016-03-12 00:42:00 +03:00
|
|
|
|
|
|
|
@pytest.mark.parametrize('exit_status', [0, 1, 2, 32, 64, 127, 254, 255])
|
2016-06-17 22:47:34 +03:00
|
|
|
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
|
|
|
|
def test_exit_status_regular_exit(exit_status):
|
2015-09-12 01:57:22 +03:00
|
|
|
"""dumb-init should exit with the same exit status as the process that it
|
2016-03-12 00:42:00 +03:00
|
|
|
supervises when that process exits normally.
|
|
|
|
"""
|
|
|
|
proc = Popen(('dumb-init', 'sh', '-c', 'exit {0}'.format(exit_status)))
|
|
|
|
proc.wait()
|
|
|
|
assert proc.returncode == exit_status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('signal', [
|
|
|
|
signal.SIGTERM,
|
2016-08-26 23:22:55 +03:00
|
|
|
signal.SIGHUP,
|
2016-03-12 00:42:00 +03:00
|
|
|
signal.SIGQUIT,
|
|
|
|
signal.SIGKILL,
|
|
|
|
])
|
2016-06-17 22:47:34 +03:00
|
|
|
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
|
|
|
|
def test_exit_status_terminated_by_signal(signal):
|
2016-03-12 00:42:00 +03:00
|
|
|
"""dumb-init should exit with status 128 + signal when the child process is
|
|
|
|
terminated by a signal.
|
2015-09-12 01:57:22 +03:00
|
|
|
"""
|
2016-08-26 23:22:55 +03:00
|
|
|
# We use Python because sh is "dash" on Debian and "bash" on others.
|
2016-08-26 23:04:46 +03:00
|
|
|
# https://github.com/Yelp/dumb-init/issues/115
|
2016-08-26 23:22:55 +03:00
|
|
|
proc = Popen(('dumb-init', sys.executable, '-c', 'import os; os.kill(os.getpid(), {0})'.format(
|
2016-08-26 23:04:46 +03:00
|
|
|
signal,
|
|
|
|
)))
|
2016-03-12 00:42:00 +03:00
|
|
|
proc.wait()
|
|
|
|
assert proc.returncode == 128 + signal
|