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 bgact = BogusActor.start(OSError(errno.ENOENT, ""), killfunc=kill_mock)
52 act_thread = bgact.proxy().get_thread().get()
53 act = bgact.tell_proxy()
55 act.actor_ref.stop(block=True)
57 self.assertFalse(kill_mock.called)
58 self.assertEqual(1, status.tracker.get('actor_exceptions'))
60 class WatchdogActorTest(testutil.ActorTestMixin, unittest.TestCase):
62 def test_time_timout(self):
63 kill_mock = mock.Mock('os.kill')
64 act = BogusActor.start(OSError(errno.ENOENT, ""))
65 watch = arvnodeman.baseactor.WatchdogActor.start(1, act, killfunc=kill_mock)
67 watch.stop(block=True)
69 self.assertTrue(kill_mock.called)