2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
17 from . import testutil
19 import arvnodeman.baseactor
20 import arvnodeman.status as status
22 class BogusActor(arvnodeman.baseactor.BaseNodeManagerActor):
23 def __init__(self, e, killfunc=None):
24 super(BogusActor, self).__init__(killfunc=killfunc)
31 # Called by WatchdogActorTest, this delay is longer than the test timeout
32 # of 1 second, which should cause the watchdog ping to fail.
36 class ActorUnhandledExceptionTest(testutil.ActorTestMixin, unittest.TestCase):
37 def test_fatal_error(self):
38 for e in (MemoryError(), threading.ThreadError(), OSError(errno.ENOMEM, "")):
39 kill_mock = mock.Mock('os.kill')
40 bgact = BogusActor.start(e, killfunc=kill_mock)
41 act_thread = bgact.proxy().get_thread().get()
42 act = bgact.tell_proxy()
44 act.actor_ref.stop(block=True)
46 self.assertTrue(kill_mock.called)
48 def test_nonfatal_error(self):
49 status.tracker.update({'actor_exceptions': 0})
50 kill_mock = mock.Mock('os.kill')
51 act = BogusActor.start(OSError(errno.ENOENT, ""), killfunc=kill_mock).tell_proxy()
53 act.actor_ref.stop(block=True)
54 self.assertFalse(kill_mock.called)
55 self.assertEqual(1, status.tracker.get('actor_exceptions'))
57 class WatchdogActorTest(testutil.ActorTestMixin, unittest.TestCase):
59 def test_time_timout(self):
60 kill_mock = mock.Mock('os.kill')
61 act = BogusActor.start(OSError(errno.ENOENT, ""))
62 watch = arvnodeman.baseactor.WatchdogActor.start(1, act, killfunc=kill_mock)
64 watch.stop(block=True)
66 self.assertTrue(kill_mock.called)