Try stop with SIGINT first, pass timeout to constructor

This commit is contained in:
Anton Ermak
2018-01-09 19:23:24 +07:00
parent 2b754d2662
commit 21779b6d0d
2 changed files with 42 additions and 3 deletions

View File

@@ -16,3 +16,24 @@ def test_watchdog_kill(caplog):
log = ["Watchdog started", "Watchdog stopped"]
for line in log:
assert line in caplog.text
def test_try_kill_failed(mocker):
mocker.patch("os.kill")
mocker.patch("os.waitpid", return_value=(0, 0))
watchdog = Watchdog(1, 1)
assert watchdog.try_kill(0) is False
def test_try_kill_success(mocker):
mocker.patch("os.kill")
mocker.patch("os.waitpid", return_value=(0, 1))
watchdog = Watchdog(1, 1)
assert watchdog.try_kill(0) is True
def test_try_kill_error(mocker):
mocker.patch("os.kill")
mocker.patch("os.waitpid", side_effect=OSError)
watchdog = Watchdog(1, 1)
assert watchdog.try_kill(0) is True