forked from goodboy/tractor
1
0
Fork 0

Merge pull request #2 from goodboy/start_up_sequence_trickery

Start up sequence trickery
matrix
Guillermo Rodriguez 2020-07-29 15:02:51 -03:00 committed by GitHub
commit a565d38251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -4,6 +4,7 @@ Cancellation and error propagation
import os import os
import signal import signal
import platform import platform
import time
from itertools import repeat from itertools import repeat
import pytest import pytest
@ -359,7 +360,11 @@ async def test_nested_multierrors(loglevel, start_method):
@no_windows @no_windows
def test_cancel_via_SIGINT(loglevel, start_method): def test_cancel_via_SIGINT(
loglevel,
start_method,
spawn_backend,
):
"""Ensure that a control-C (SIGINT) signal cancels both the parent and """Ensure that a control-C (SIGINT) signal cancels both the parent and
child processes in trionic fashion child processes in trionic fashion
""" """
@ -369,6 +374,8 @@ def test_cancel_via_SIGINT(loglevel, start_method):
with trio.fail_after(2): with trio.fail_after(2):
async with tractor.open_nursery() as tn: async with tractor.open_nursery() as tn:
await tn.start_actor('sucka') await tn.start_actor('sucka')
if spawn_backend == 'mp':
time.sleep(0.1)
os.kill(pid, signal.SIGINT) os.kill(pid, signal.SIGINT)
await trio.sleep_forever() await trio.sleep_forever()
@ -379,7 +386,8 @@ def test_cancel_via_SIGINT(loglevel, start_method):
@no_windows @no_windows
def test_cancel_via_SIGINT_other_task( def test_cancel_via_SIGINT_other_task(
loglevel, loglevel,
start_method start_method,
spawn_backend,
): ):
"""Ensure that a control-C (SIGINT) signal cancels both the parent """Ensure that a control-C (SIGINT) signal cancels both the parent
and child processes in trionic fashion even a subprocess is started and child processes in trionic fashion even a subprocess is started
@ -399,6 +407,8 @@ def test_cancel_via_SIGINT_other_task(
with trio.fail_after(2): with trio.fail_after(2):
async with trio.open_nursery() as n: async with trio.open_nursery() as n:
await n.start(spawn_and_sleep_forever) await n.start(spawn_and_sleep_forever)
if spawn_backend == 'mp':
time.sleep(0.1)
os.kill(pid, signal.SIGINT) os.kill(pid, signal.SIGINT)
with pytest.raises(KeyboardInterrupt): with pytest.raises(KeyboardInterrupt):

View File

@ -202,7 +202,11 @@ async def cancel_after(wait):
@pytest.fixture(scope='module') @pytest.fixture(scope='module')
def time_quad_ex(arb_addr): def time_quad_ex(arb_addr, travis, spawn_backend):
if travis and spawn_backend == 'mp' and (platform.system() != 'Windows'):
# no idea, but the travis, mp, linux runs are flaking out here often
pytest.skip("Test is too flaky on mp in CI")
timeout = 7 if platform.system() == 'Windows' else 4 timeout = 7 if platform.system() == 'Windows' else 4
start = time.time() start = time.time()
results = tractor.run(cancel_after, timeout, arbiter_addr=arb_addr) results = tractor.run(cancel_after, timeout, arbiter_addr=arb_addr)
@ -213,9 +217,6 @@ def time_quad_ex(arb_addr):
def test_a_quadruple_example(time_quad_ex, travis, spawn_backend): def test_a_quadruple_example(time_quad_ex, travis, spawn_backend):
"""This also serves as a kind of "we'd like to be this fast test".""" """This also serves as a kind of "we'd like to be this fast test"."""
if travis and spawn_backend == 'mp' and (platform.system() != 'Windows'):
# no idea, but the travis, mp, linux runs are flaking out here often
pytest.skip("Test is too flaky on mp in CI")
results, diff = time_quad_ex results, diff = time_quad_ex
assert results assert results
@ -233,10 +234,6 @@ def test_not_fast_enough_quad(
"""Verify we can cancel midway through the quad example and all actors """Verify we can cancel midway through the quad example and all actors
cancel gracefully. cancel gracefully.
""" """
if travis and spawn_backend == 'mp' and (platform.system() != 'Windows'):
# no idea, but the travis, mp, linux runs are flaking out here often
pytest.skip("Test is too flaky on mp in CI")
results, diff = time_quad_ex results, diff = time_quad_ex
delay = max(diff - cancel_delay, 0) delay = max(diff - cancel_delay, 0)
results = tractor.run(cancel_after, delay, arbiter_addr=arb_addr) results = tractor.run(cancel_after, delay, arbiter_addr=arb_addr)