8437: Test all exceptions that should be caught.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 29 Feb 2016 15:33:27 +0000 (10:33 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 29 Feb 2016 15:33:27 +0000 (10:33 -0500)
services/nodemanager/tests/test_failure.py

index b7127fc2bbddf4ea2c9fd0c22dc746ec4baae6f2..afebb9ca32e0b5c167a96260a566feb81df3a45d 100644 (file)
@@ -2,7 +2,9 @@
 
 from __future__ import absolute_import, print_function
 
+import errno
 import logging
+import threading
 import unittest
 
 import mock
@@ -13,13 +15,29 @@ from . import testutil
 import arvnodeman.fullstopactor
 
 class BogusActor(arvnodeman.fullstopactor.FullStopActor):
+    def __init__(self, e):
+        super(BogusActor, self).__init__()
+        self.exp = e
+
     def doStuff(self):
-        raise MemoryError
+        raise self.exp
 
 class ActorUnhandledExceptionTest(unittest.TestCase):
     def test1(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()
+            act = BogusActor.start(OSError(errno.ENOENT, ""))
             act.tell({
                 'command': 'pykka_call',
                 'attr_path': ("doStuff",),
@@ -27,4 +45,4 @@ class ActorUnhandledExceptionTest(unittest.TestCase):
                 'kwargs': {}
             })
             act.stop(block=True)
-            self.assertTrue(killpg_mock.called)
+            self.assertFalse(killpg_mock.called)