Skip to content

Commit

Permalink
use crash that will also kill a Windows engine
Browse files Browse the repository at this point in the history
crash is from the Python test suite

Windows crash dialog is suppressed prior to crash

also fixed 'assertRaisesRemote' message, which had names backwards
  • Loading branch information
minrk committed Apr 20, 2011
1 parent 0d3d807 commit 151aca8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
13 changes: 12 additions & 1 deletion IPython/parallel/tests/clienttest.py
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +97,7 @@ def assertRaisesRemote(self, etype, f, *args, **kwargs):
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")

Expand Down
18 changes: 11 additions & 7 deletions IPython/parallel/tests/test_view.py
Expand Up @@ -25,33 +25,37 @@

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"""
Expand Down

0 comments on commit 151aca8

Please sign in to comment.