Skip to content

Commit 91b273a

Browse files
authored
Merge pull request #453 from minrk/crash-test
regression tests for outstanding, engine crash
2 parents 103f030 + 93397a0 commit 91b273a

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

ipyparallel/tests/clienttest.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""base class for parallel client tests"""
22
from __future__ import print_function
33

4+
import os
45
import sys
56
import time
67

@@ -25,24 +26,8 @@ def segfault():
2526

2627

2728
def crash():
28-
"""from stdlib crashers in the test suite"""
29-
import types
30-
31-
if sys.platform.startswith('win'):
32-
import ctypes
33-
34-
ctypes.windll.kernel32.SetErrorMode(0x0002)
35-
args = [0, 0, 0, 0, b'\x04\x71\x00\x00', (), (), (), '', '', 1, b'']
36-
if sys.version_info[0] >= 3:
37-
# Python3 adds 'kwonlyargcount' as the second argument to Code
38-
args.insert(1, 0)
39-
if sys.version_info > (3, 8):
40-
# Python 3.8 adds 'posonlyargcount' as the second argument to Code
41-
# kwonlyargcount added above is now the third argument
42-
args.insert(1, 0)
43-
44-
co = types.CodeType(*args)
45-
exec(co)
29+
"""Ungracefully exit the process"""
30+
os._exit(1)
4631

4732

4833
def wait(n):

ipyparallel/tests/test_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ def test_view_indexing(self):
7070
self.assertEqual(v.targets, targets[-1])
7171
self.assertRaises(TypeError, lambda: self.client[None])
7272

73+
def test_outstanding(self):
74+
self.minimum_engines(1)
75+
e = self.client[-1]
76+
engine_id = self.client._engines[e.targets]
77+
ar = e.apply_async(time.sleep, 0.5)
78+
msg_id = ar.msg_ids[0]
79+
# verify that msg id
80+
assert msg_id in self.client.outstanding
81+
assert msg_id in self.client._outstanding_dict[engine_id]
82+
ar.get()
83+
assert msg_id not in self.client.outstanding
84+
assert msg_id not in self.client._outstanding_dict[engine_id]
85+
7386
def test_lbview_targets(self):
7487
"""test load_balanced_view targets"""
7588
v = self.client.load_balanced_view()

ipyparallel/tests/test_lbview.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ def setUp(self):
2020
ClusterTestCase.setUp(self)
2121
self.view = self.client.load_balanced_view()
2222

23-
@pytest.mark.xfail
24-
def test_z_crash_task(self):
23+
def test_z_crash(self):
2524
"""test graceful handling of engine death (balanced)"""
26-
# self.add_engines(1)
25+
self.add_engines(1)
2726
ar = self.view.apply_async(crash)
2827
self.assertRaisesRemote(error.EngineError, ar.get, 10)
2928
eid = ar.engine_id
3029
tic = time.time()
3130
while eid in self.client.ids and time.time() - tic < 5:
3231
time.sleep(0.01)
33-
self.assertFalse(eid in self.client.ids, "Engine should have died")
32+
assert eid not in self.client.ids
3433

3534
def test_map(self):
3635
def f(x):

ipyparallel/tests/test_view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ def setUp(self):
3939
time.sleep(2)
4040
super(TestView, self).setUp()
4141

42-
@pytest.mark.xfail
4342
def test_z_crash_mux(self):
4443
"""test graceful handling of engine death (direct)"""
45-
# self.add_engines(1)
44+
self.add_engines(1)
4645
eid = self.client.ids[-1]
4746
ar = self.client[eid].apply_async(crash)
4847
self.assertRaisesRemote(error.EngineError, ar.get, 10)
4948
eid = ar.engine_id
5049
tic = time.time()
5150
while eid in self.client.ids and time.time() - tic < 5:
5251
time.sleep(0.01)
53-
self.assertFalse(eid in self.client.ids, "Engine should have died")
52+
assert eid not in self.client.ids
5453

5554
def test_push_pull(self):
5655
"""test pushing and pulling"""

0 commit comments

Comments
 (0)