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
21 class BogusActor(arvnodeman.baseactor.BaseNodeManagerActor):
22 def __init__(self, e):
23 super(BogusActor, self).__init__()
30 # Called by WatchdogActorTest, this delay is longer than the test timeout
31 # of 1 second, which should cause the watchdog ping to fail.
35 class ActorUnhandledExceptionTest(testutil.ActorTestMixin, unittest.TestCase):
36 def test_fatal_error(self):
37 for e in (MemoryError(), threading.ThreadError(), OSError(errno.ENOMEM, "")):
38 with mock.patch('os.kill') as kill_mock:
39 act = BogusActor.start(e).tell_proxy()
41 act.actor_ref.stop(block=True)
42 self.assertTrue(kill_mock.called)
44 @mock.patch('os.kill')
45 def test_nonfatal_error(self, kill_mock):
46 act = BogusActor.start(OSError(errno.ENOENT, "")).tell_proxy()
48 act.actor_ref.stop(block=True)
49 self.assertFalse(kill_mock.called)
51 class WatchdogActorTest(testutil.ActorTestMixin, unittest.TestCase):
52 @mock.patch('os.kill')
53 def test_time_timout(self, kill_mock):
54 act = BogusActor.start(OSError(errno.ENOENT, ""))
55 watch = arvnodeman.baseactor.WatchdogActor.start(1, act)
56 watch.stop(block=True)
58 self.assertTrue(kill_mock.called)