1
1
import asyncio
2
+ import logging
2
3
import shutil
3
4
import signal
5
+ import sys
4
6
import time
5
7
6
8
import pytest
9
+ from traitlets .config import Config
7
10
8
11
from .clienttest import raises_remote
9
12
from ipyparallel import cluster
10
- from ipyparallel .cluster import launcher
13
+ from ipyparallel .cluster . launcher import find_launcher_class
11
14
12
15
13
16
@pytest .fixture
14
17
def Cluster (request ):
15
18
"""Fixture for instantiating Clusters"""
16
19
17
20
def ClusterConstructor (** kwargs ):
18
- kwargs .setdefault ('log_level' , 10 )
19
- launcher_prefix = kwargs .pop ("launcher_prefix" )
20
-
21
- if launcher_prefix == "MPI" and shutil .which ("mpiexec" ) is None :
21
+ log = logging .getLogger (__file__ )
22
+ log .setLevel (logging .DEBUG )
23
+ log .handlers = [logging .StreamHandler (sys .stdout )]
24
+ kwargs ['log' ] = log
25
+ engine_launcher_class = kwargs .get ("engine_launcher_class" )
26
+
27
+ if (
28
+ isinstance (engine_launcher_class , str )
29
+ and "MPI" in engine_launcher_class
30
+ and shutil .which ("mpiexec" ) is None
31
+ ):
22
32
pytest .skip ("requires mpiexec" )
23
- launcher_class = launcher .find_launcher_class (launcher_prefix , "EngineSet" )
24
- kwargs ['engine_launcher_class' ] = launcher_class
33
+
34
+ cfg = kwargs .setdefault ("config" , Config ())
35
+ cfg .EngineMixin .engine_args = ['--log-level=10' ]
36
+ cfg .ControllerMixin .controller_args = ['--log-level=10' ]
25
37
26
38
c = cluster .Cluster (** kwargs )
27
39
request .addfinalizer (c .stop_cluster_sync )
@@ -59,14 +71,14 @@ async def test_start_stop_controller(Cluster):
59
71
# TODO: test file cleanup
60
72
61
73
62
- @pytest .mark .parametrize ("launcher_prefix " , ["Local" , "MPI" ])
63
- async def test_start_stop_engines (Cluster , launcher_prefix ):
64
- cluster = Cluster (launcher_prefix = launcher_prefix )
74
+ @pytest .mark .parametrize ("engine_launcher_class " , ["Local" , "MPI" ])
75
+ async def test_start_stop_engines (Cluster , engine_launcher_class ):
76
+ cluster = Cluster (engine_launcher_class = engine_launcher_class )
65
77
await cluster .start_controller ()
66
78
engine_set_id = await cluster .start_engines (n = 3 )
67
79
assert engine_set_id in cluster ._engine_sets
68
80
engine_set = cluster ._engine_sets [engine_set_id ]
69
- launcher_class = launcher_class = find_launcher_class (launcher_prefix , "EngineSet" )
81
+ launcher_class = find_launcher_class (engine_launcher_class , "EngineSet" )
70
82
assert isinstance (engine_set , launcher_class )
71
83
await cluster .stop_engines (engine_set_id )
72
84
assert cluster ._engine_sets == {}
@@ -76,20 +88,28 @@ async def test_start_stop_engines(Cluster, launcher_prefix):
76
88
await cluster .stop_controller ()
77
89
78
90
79
- @pytest .mark .parametrize ("launcher_prefix " , ["Local" , "MPI" ])
80
- async def test_signal_engines (Cluster , launcher_prefix ):
81
- cluster = Cluster (launcher_prefix = launcher_prefix )
91
+ @pytest .mark .parametrize ("engine_launcher_class " , ["Local" , "MPI" ])
92
+ async def test_signal_engines (Cluster , engine_launcher_class ):
93
+ cluster = Cluster (engine_launcher_class = engine_launcher_class )
82
94
await cluster .start_controller ()
83
95
engine_set_id = await cluster .start_engines (n = 3 )
84
96
rc = cluster .connect_client ()
85
97
while len (rc ) < 3 :
86
98
await asyncio .sleep (0.1 )
99
+ # seems to be a problem if we start too soon...
100
+ await asyncio .sleep (1 )
101
+ # ensure responsive
102
+ rc [:].apply_async (lambda : None ).get (timeout = 10 )
103
+ # submit request to be interrupted
87
104
ar = rc [:].apply_async (time .sleep , 3 )
105
+ # wait for it to be running
88
106
await asyncio .sleep (0.5 )
107
+ # send signal
89
108
await cluster .signal_engines (engine_set_id , signal .SIGINT )
90
109
110
+ # wait for result, which should raise KeyboardInterrupt
91
111
with raises_remote (KeyboardInterrupt ) as e :
92
- ar .get ()
112
+ ar .get (timeout = 10 )
93
113
94
114
await cluster .stop_engines ()
95
115
await cluster .stop_controller ()
0 commit comments