3 from __future__ import absolute_import, print_function
14 from . import testutil
16 import arvnodeman.baseactor
18 class BogusActor(arvnodeman.baseactor.BaseNodeManagerActor):
19 def __init__(self, e):
20 super(BogusActor, self).__init__()
27 # Called by WatchdogActorTest, this delay is longer than the test timeout
28 # of 1 second, which should cause the watchdog ping to fail.
32 class ActorUnhandledExceptionTest(testutil.ActorTestMixin, unittest.TestCase):
33 def test_fatal_error(self):
34 for e in (MemoryError(), threading.ThreadError(), OSError(errno.ENOMEM, "")):
35 with mock.patch('os.kill') as kill_mock:
36 act = BogusActor.start(e).tell_proxy()
38 act.actor_ref.stop(block=True)
39 self.assertTrue(kill_mock.called)
41 @mock.patch('os.kill')
42 def test_nonfatal_error(self, kill_mock):
43 act = BogusActor.start(OSError(errno.ENOENT, "")).tell_proxy()
45 act.actor_ref.stop(block=True)
46 self.assertFalse(kill_mock.called)
48 class WatchdogActorTest(testutil.ActorTestMixin, unittest.TestCase):
49 @mock.patch('os.kill')
50 def test_time_timout(self, kill_mock):
51 act = BogusActor.start(OSError(errno.ENOENT, ""))
52 watch = arvnodeman.baseactor.WatchdogActor.start(1, act)
53 watch.stop(block=True)
55 self.assertTrue(kill_mock.called)