diff --git a/IPython/parallel/tests/clienttest.py b/IPython/parallel/tests/clienttest.py index a6e4300..8cee15f 100644 --- a/IPython/parallel/tests/clienttest.py +++ b/IPython/parallel/tests/clienttest.py @@ -29,6 +29,17 @@ def segfault(): import ctypes ctypes.memset(-1,0,1) +def crash(): + """from stdlib crashers in the test suite""" + import types + if sys.platform.startswith('win'): + import ctypes + ctypes.windll.kernel32.SetErrorMode(0x0002); + + co = types.CodeType(0, 0, 0, 0, b'\x04\x71\x00\x00', + (), (), (), '', '', 1, b'') + exec(co) + def wait(n): """sleep for a time""" import time @@ -86,7 +97,7 @@ class ClusterTestCase(BaseZMQTestCase): except error.CompositeError as e: e.raise_exception() except error.RemoteError as e: - self.assertEquals(etype.__name__, e.ename, "Should have raised %r, but raised %r"%(e.ename, etype.__name__)) + self.assertEquals(etype.__name__, e.ename, "Should have raised %r, but raised %r"%(etype.__name__, e.ename)) else: self.fail("should have raised a RemoteError") diff --git a/IPython/parallel/tests/test_view.py b/IPython/parallel/tests/test_view.py index f28cc30..d076881 100644 --- a/IPython/parallel/tests/test_view.py +++ b/IPython/parallel/tests/test_view.py @@ -25,33 +25,37 @@ from IPython.parallel.util import interactive from IPython.parallel.tests import add_engines -from .clienttest import ClusterTestCase, segfault, wait, skip_without +from .clienttest import ClusterTestCase, crash, wait, skip_without def setup(): add_engines(3) class TestView(ClusterTestCase): - def test_segfault_task(self): + def test_crash_task(self): """test graceful handling of engine death (balanced)""" # self.add_engines(1) - ar = self.client[-1].apply_async(segfault) + ar = self.client[-1].apply_async(crash) self.assertRaisesRemote(error.EngineError, ar.get) eid = ar.engine_id - while eid in self.client.ids: + tic = time.time() + while eid in self.client.ids and time.time()-tic < 5: time.sleep(.01) self.client.spin() + self.assertFalse(eid in self.client.ids, "Engine should have died") - def test_segfault_mux(self): + def test_crash_mux(self): """test graceful handling of engine death (direct)""" # self.add_engines(1) eid = self.client.ids[-1] - ar = self.client[eid].apply_async(segfault) + ar = self.client[eid].apply_async(crash) self.assertRaisesRemote(error.EngineError, ar.get) eid = ar.engine_id - while eid in self.client.ids: + tic = time.time() + while eid in self.client.ids and time.time()-tic < 5: time.sleep(.01) self.client.spin() + self.assertFalse(eid in self.client.ids, "Engine should have died") def test_push_pull(self): """test pushing and pulling"""