15
15
from IPython .utils .io import capture_output
16
16
from ipython_genutils .py3compat import unicode_type
17
17
18
- import ipyparallel as pmod
18
+ import ipyparallel as ipp
19
19
from .clienttest import ClusterTestCase
20
- from .clienttest import crash
20
+ from .clienttest import conditional_crash
21
21
from .clienttest import skip_without
22
22
from .clienttest import wait
23
23
from ipyparallel import AsyncHubResult
24
24
from ipyparallel import AsyncMapResult
25
25
from ipyparallel import AsyncResult
26
26
from ipyparallel import error
27
- from ipyparallel .tests import add_engines
28
27
from ipyparallel .util import interactive
29
28
30
29
point = namedtuple ("point" , "x y" )
@@ -42,13 +41,15 @@ def setUp(self):
42
41
def test_z_crash_mux (self ):
43
42
"""test graceful handling of engine death (direct)"""
44
43
self .add_engines (1 )
44
+ self .minimum_engines (2 )
45
45
eid = self .client .ids [- 1 ]
46
- ar = self .client [eid ].apply_async (crash )
46
+ view = self .client [- 2 :]
47
+ view .scatter ('should_crash' , [False , True ], flatten = True )
48
+ ar = view .apply_async (conditional_crash , ipp .Reference ("should_crash" ))
47
49
self .assertRaisesRemote (error .EngineError , ar .get , 10 )
48
- eid = ar .engine_id
49
- tic = time .time ()
50
- while eid in self .client .ids and time .time () - tic < 5 :
51
- time .sleep (0.01 )
50
+ tic = time .perf_counter ()
51
+ while eid in self .client .ids and time .perf_counter () - tic < 5 :
52
+ time .sleep (0.05 )
52
53
assert eid not in self .client .ids
53
54
54
55
def test_push_pull (self ):
@@ -135,7 +136,7 @@ def echo(a=10):
135
136
136
137
def test_get_result (self ):
137
138
"""test getting results from the Hub."""
138
- c = pmod .Client (profile = 'iptest' )
139
+ c = ipp .Client (profile = 'iptest' )
139
140
# self.add_engines(1)
140
141
t = c .ids [- 1 ]
141
142
v = c [t ]
@@ -161,7 +162,7 @@ def test_run_newline(self):
161
162
)
162
163
v = self .client [- 1 ]
163
164
v .run (f .name , block = True )
164
- self .assertEqual (v .apply_sync (lambda f : f (), pmod .Reference ('g' )), 5 )
165
+ self .assertEqual (v .apply_sync (lambda f : f (), ipp .Reference ('g' )), 5 )
165
166
166
167
def test_apply_tracked (self ):
167
168
"""test tracking for apply"""
@@ -215,7 +216,7 @@ def test_scatter_tracked(self):
215
216
def test_remote_reference (self ):
216
217
v = self .client [- 1 ]
217
218
v ['a' ] = 123
218
- ra = pmod .Reference ('a' )
219
+ ra = ipp .Reference ('a' )
219
220
b = v .apply_sync (lambda x : x , ra )
220
221
self .assertEqual (b , 123 )
221
222
@@ -472,7 +473,7 @@ def test_map_reference(self):
472
473
v = self .client [:]
473
474
v .scatter ('n' , self .client .ids , flatten = True )
474
475
v .execute ("f = lambda x,y: x*y" )
475
- rf = pmod .Reference ('f' )
476
+ rf = ipp .Reference ('f' )
476
477
nlist = list (range (10 ))
477
478
mlist = nlist [::- 1 ]
478
479
expected = [m * n for m , n in zip (mlist , nlist )]
@@ -484,21 +485,21 @@ def test_apply_reference(self):
484
485
v = self .client [:]
485
486
v .scatter ('n' , self .client .ids , flatten = True )
486
487
v .execute ("f = lambda x: n*x" )
487
- rf = pmod .Reference ('f' )
488
+ rf = ipp .Reference ('f' )
488
489
result = v .apply_sync (rf , 5 )
489
490
expected = [5 * id for id in self .client .ids ]
490
491
self .assertEqual (result , expected )
491
492
492
493
def test_eval_reference (self ):
493
494
v = self .client [self .client .ids [0 ]]
494
495
v ['g' ] = list (range (5 ))
495
- rg = pmod .Reference ('g[0]' )
496
+ rg = ipp .Reference ('g[0]' )
496
497
echo = lambda x : x
497
498
self .assertEqual (v .apply_sync (echo , rg ), 0 )
498
499
499
500
def test_reference_nameerror (self ):
500
501
v = self .client [self .client .ids [0 ]]
501
- r = pmod .Reference ('elvis_has_left' )
502
+ r = ipp .Reference ('elvis_has_left' )
502
503
echo = lambda x : x
503
504
self .assertRaisesRemote (NameError , v .apply_sync , echo , r )
504
505
@@ -745,7 +746,7 @@ def test_can_list_arg(self):
745
746
"""args in lists are canned"""
746
747
view = self .client [- 1 ]
747
748
view ['a' ] = 128
748
- rA = pmod .Reference ('a' )
749
+ rA = ipp .Reference ('a' )
749
750
ar = view .apply_async (lambda x : x , [rA ])
750
751
r = ar .get (5 )
751
752
self .assertEqual (r , [128 ])
@@ -754,7 +755,7 @@ def test_can_dict_arg(self):
754
755
"""args in dicts are canned"""
755
756
view = self .client [- 1 ]
756
757
view ['a' ] = 128
757
- rA = pmod .Reference ('a' )
758
+ rA = ipp .Reference ('a' )
758
759
ar = view .apply_async (lambda x : x , dict (foo = rA ))
759
760
r = ar .get (5 )
760
761
self .assertEqual (r , dict (foo = 128 ))
@@ -763,7 +764,7 @@ def test_can_list_kwarg(self):
763
764
"""kwargs in lists are canned"""
764
765
view = self .client [- 1 ]
765
766
view ['a' ] = 128
766
- rA = pmod .Reference ('a' )
767
+ rA = ipp .Reference ('a' )
767
768
ar = view .apply_async (lambda x = 5 : x , x = [rA ])
768
769
r = ar .get (5 )
769
770
self .assertEqual (r , [128 ])
@@ -772,7 +773,7 @@ def test_can_dict_kwarg(self):
772
773
"""kwargs in dicts are canned"""
773
774
view = self .client [- 1 ]
774
775
view ['a' ] = 128
775
- rA = pmod .Reference ('a' )
776
+ rA = ipp .Reference ('a' )
776
777
ar = view .apply_async (lambda x = 5 : x , dict (foo = rA ))
777
778
r = ar .get (5 )
778
779
self .assertEqual (r , dict (foo = 128 ))
@@ -782,7 +783,7 @@ def test_map_ref(self):
782
783
view = self .client [:]
783
784
ranks = sorted (self .client .ids )
784
785
view .scatter ('rank' , ranks , flatten = True )
785
- rrank = pmod .Reference ('rank' )
786
+ rrank = ipp .Reference ('rank' )
786
787
787
788
amr = view .map_async (lambda x : x * 2 , [rrank ] * len (view ))
788
789
drank = amr .get (5 )
@@ -801,7 +802,7 @@ def test_nested_getitem_setitem(self):
801
802
),
802
803
block = True ,
803
804
)
804
- ra = pmod .Reference ('a' )
805
+ ra = ipp .Reference ('a' )
805
806
806
807
r = view .apply_sync (lambda x : x .b , ra )
807
808
self .assertEqual (r , 128 )
0 commit comments