X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6ed351ec65d657c27b48b4e4ac0c89d880a2fd1a..224f384d411bb1b4cccc7165c55bb64fd5c695ad:/services/nodemanager/tests/test_failure.py diff --git a/services/nodemanager/tests/test_failure.py b/services/nodemanager/tests/test_failure.py index afebb9ca32..dea7230dd3 100644 --- a/services/nodemanager/tests/test_failure.py +++ b/services/nodemanager/tests/test_failure.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function import errno import logging +import time import threading import unittest @@ -12,9 +13,9 @@ import pykka from . import testutil -import arvnodeman.fullstopactor +import arvnodeman.baseactor -class BogusActor(arvnodeman.fullstopactor.FullStopActor): +class BogusActor(arvnodeman.baseactor.BaseNodeManagerActor): def __init__(self, e): super(BogusActor, self).__init__() self.exp = e @@ -22,27 +23,33 @@ class BogusActor(arvnodeman.fullstopactor.FullStopActor): def doStuff(self): raise self.exp + def ping(self): + # Called by WatchdogActorTest, this delay is longer than the test timeout + # of 1 second, which should cause the watchdog ping to fail. + time.sleep(2) + return True + class ActorUnhandledExceptionTest(unittest.TestCase): - def test1(self): + def test_fatal_error(self): for e in (MemoryError(), threading.ThreadError(), OSError(errno.ENOMEM, "")): - with mock.patch('os.killpg') as killpg_mock: - act = BogusActor.start(e) - act.tell({ - 'command': 'pykka_call', - 'attr_path': ("doStuff",), - 'args': [], - 'kwargs': {} - }) - act.stop(block=True) - self.assertTrue(killpg_mock.called) - - with mock.patch('os.killpg') as killpg_mock: - act = BogusActor.start(OSError(errno.ENOENT, "")) - act.tell({ - 'command': 'pykka_call', - 'attr_path': ("doStuff",), - 'args': [], - 'kwargs': {} - }) - act.stop(block=True) - self.assertFalse(killpg_mock.called) + with mock.patch('os.kill') as kill_mock: + act = BogusActor.start(e).tell_proxy() + act.doStuff() + act.actor_ref.stop(block=True) + self.assertTrue(kill_mock.called) + + @mock.patch('os.kill') + def test_nonfatal_error(self, kill_mock): + act = BogusActor.start(OSError(errno.ENOENT, "")).tell_proxy() + act.doStuff() + act.actor_ref.stop(block=True) + self.assertFalse(kill_mock.called) + +class WatchdogActorTest(unittest.TestCase): + @mock.patch('os.kill') + def test_time_timout(self, kill_mock): + act = BogusActor.start(OSError(errno.ENOENT, "")) + watch = arvnodeman.baseactor.WatchdogActor.start(1, act) + watch.stop(block=True) + act.stop(block=True) + self.assertTrue(kill_mock.called)