forked from goodboy/tractor
1
0
Fork 0

multi_program signal for windows missing SIGKILL, SIGINT

propagate_loglevel
Christian López Barrón 2019-03-10 14:48:50 +11:00
parent 2138d55a60
commit 5fc51fd745
1 changed files with 24 additions and 6 deletions

View File

@ -8,8 +8,19 @@ import subprocess
import pytest import pytest
import tractor import tractor
import platform
from conftest import tractor_test from conftest import tractor_test
# Sending signal.SIGINT on subprocess fails on windows. Use CTRL_* alternatives
if platform.system() == 'Windows':
_KILL_SIGNAL = signal.CTRL_BREAK_EVENT
_INT_SIGNAL = signal.CTRL_C_EVENT
_INT_RETURN_CODE = 3221225786
else:
_KILL_SIGNAL = signal.SIGKILL
_INT_SIGNAL = signal.SIGINT
_INT_RETURN_CODE = 1
def sig_prog(proc, sig): def sig_prog(proc, sig):
"Kill the actor-process with ``sig``." "Kill the actor-process with ``sig``."
@ -18,8 +29,7 @@ def sig_prog(proc, sig):
if not proc.poll(): if not proc.poll():
# TODO: why sometimes does SIGINT not work on teardown? # TODO: why sometimes does SIGINT not work on teardown?
# seems to happen only when trace logging enabled? # seems to happen only when trace logging enabled?
proc.send_signal(signal.SIGKILL) proc.send_signal(_KILL_SIGNAL)
ret = proc.wait() ret = proc.wait()
assert ret assert ret
@ -33,25 +43,33 @@ def daemon(loglevel, testdir, arb_addr):
arb_addr, arb_addr,
"'{}'".format(loglevel) if loglevel else None) "'{}'".format(loglevel) if loglevel else None)
] ]
kwargs = dict()
if platform.system() == 'Windows':
# without this, tests hang on windows forever
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
proc = testdir.popen( proc = testdir.popen(
cmdargs, cmdargs,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
**kwargs,
) )
assert not proc.returncode assert not proc.returncode
wait = 0.6 if sys.version_info < (3, 7) else 0.4 wait = 0.6 if sys.version_info < (3, 7) else 0.4
time.sleep(wait) time.sleep(wait)
yield proc yield proc
sig_prog(proc, signal.SIGINT) sig_prog(proc, _INT_SIGNAL)
def test_abort_on_sigint(daemon): def test_abort_on_sigint(daemon):
assert daemon.returncode is None assert daemon.returncode is None
time.sleep(0.1) time.sleep(0.1)
sig_prog(daemon, signal.SIGINT) sig_prog(daemon, _INT_SIGNAL)
assert daemon.returncode == 1 assert daemon.returncode == _INT_RETURN_CODE
# XXX: oddly, couldn't get capfd.readouterr() to work here? # XXX: oddly, couldn't get capfd.readouterr() to work here?
assert "KeyboardInterrupt" in str(daemon.stderr.read()) if platform.system() != 'Windows':
# don't check stderr on windows as its empty when sending CTRL_C_EVENT
assert "KeyboardInterrupt" in str(daemon.stderr.read())
@tractor_test @tractor_test