-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from chriskuehl/fix-signal-terminated-processe…
…s-exit-code Fix signal terminated processes exit code
- Loading branch information
Showing
3 changed files
with
35 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import signal | ||
from subprocess import Popen | ||
|
||
import pytest | ||
|
||
def test_exit_status(both_debug_modes, both_setsid_modes): | ||
|
||
@pytest.mark.parametrize('exit_status', [0, 1, 2, 32, 64, 127, 254, 255]) | ||
def test_exit_status_regular_exit(exit_status, both_debug_modes, both_setsid_modes): | ||
"""dumb-init should exit with the same exit status as the process that it | ||
supervises. | ||
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, | ||
signal.SIGINT, | ||
signal.SIGQUIT, | ||
signal.SIGKILL, | ||
]) | ||
def test_exit_status_terminated_by_signal(signal, both_debug_modes, both_setsid_modes): | ||
"""dumb-init should exit with status 128 + signal when the child process is | ||
terminated by a signal. | ||
""" | ||
for status in [0, 1, 2, 32, 64, 127, 254, 255]: | ||
proc = Popen(('dumb-init', 'sh', '-c', 'exit {0}'.format(status))) | ||
proc.wait() | ||
assert proc.returncode == status | ||
proc = Popen(('dumb-init', 'sh', '-c', 'kill -{0} $$'.format(signal))) | ||
proc.wait() | ||
assert proc.returncode == 128 + signal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters