Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
Delaunay committed Mar 2, 2022
1 parent 5da8211 commit d3dbfe7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
8 changes: 7 additions & 1 deletion tests/unittests/client/runner_subprocess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Used to test instantiating a runner inside a subprocess"""
from argparse import ArgumentParser

from orion.client.runner import Runner
from orion.core.utils.exceptions import WaitingForTrials
Expand All @@ -10,6 +11,11 @@
n_workers = 2


parser = ArgumentParser()
parser.add_argument("--backend", type=str, default="joblib")
args = parser.parse_args()


def new_trial(value, sleep=0.01):
"""Generate a dummy new trial"""
return Trial(
Expand All @@ -25,7 +31,7 @@ class FakeClient:

def __init__(self, n_workers):
self.is_done = False
self.executor = executor_factory.create("joblib", n_workers)
self.executor = executor_factory.create(args.backend, n_workers)
self.suggest_error = WaitingForTrials
self.trials = []
self.status = []
Expand Down
29 changes: 17 additions & 12 deletions tests/unittests/client/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def change_signal_handler(sig, handler):
class FakeClient:
"""Orion mock client for Runner."""

def __init__(self, n_workers):
def __init__(self, n_workers, backend="joblib"):
self.is_done = False
self.executor = executor_factory.create("joblib", n_workers)
self.executor = executor_factory.create(backend, n_workers)
self.suggest_error = WaitingForTrials
self.trials = []
self.status = []
Expand Down Expand Up @@ -101,10 +101,10 @@ def function(lhs, sleep):
return lhs + sleep


def new_runner(idle_timeout, n_workers=2, client=None):
def new_runner(idle_timeout, n_workers=2, client=None, backend="joblib"):
"""Create a new runner with a mock client."""
if client is None:
client = FakeClient(n_workers)
client = FakeClient(n_workers, backend=backend)

runner = Runner(
client=client,
Expand Down Expand Up @@ -538,13 +538,13 @@ def make_runner(n_workers, max_trials_per_worker, pool_size=None):
runner.client.close()


def run_runner(reraise=False, executor=None):
def run_runner(reraise=False, executor=None, backend="joblib"):
try:
count = 10
max_trials = 10
workers = 2

runner = new_runner(0.1, n_workers=workers)
runner = new_runner(0.1, n_workers=workers, backend=backend)
runner.max_trials_per_worker = max_trials
client = runner.client

Expand Down Expand Up @@ -596,7 +596,6 @@ def test_runner_inside_childprocess():
assert wpid == pid
assert exit_status == 0


def test_runner_inside_subprocess():
"""Runner can execute inside a subprocess"""

Expand All @@ -605,10 +604,10 @@ def test_runner_inside_subprocess():
dir = os.path.dirname(__file__)

result = subprocess.run(
["python", f"{dir}/runner_subprocess.py"],
["python", f"{dir}/runner_subprocess.py", "--backend", "joblib"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
)

assert result.stderr.decode("utf-8") == ""
Expand Down Expand Up @@ -636,10 +635,16 @@ def run(self):

@pytest.mark.skipif(not HAS_DASK, reason="Running without dask")
def test_runner_inside_dask():
"""Runner can execute inside a dask worker"""
"""Runner can not execute inside a dask worker"""

executor = Dask()

future = executor.submit(run_runner, executor=executor, reraise=True)
future = executor.submit(
run_runner, executor=executor, reraise=True, backend="dask"
)

with pytest.raises(AssertionError) as exc:
assert future.get() == 0

assert future.get() == 0
# Assertion Error is too broad we need to check the message as well
assert str(exc.value) == "daemonic processes are not allowed to have children"

0 comments on commit d3dbfe7

Please sign in to comment.