reraise exceptions in async tests' error handlers
authorGuido Trotter <ultrotter@google.com>
Wed, 26 May 2010 13:12:19 +0000 (14:12 +0100)
committerGuido Trotter <ultrotter@google.com>
Tue, 1 Jun 2010 08:34:46 +0000 (09:34 +0100)
This makes sure that any unforeseen error raises an exception rather
then just increasing a counter. It makes unittest debugging a lot
easier.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

test/ganeti.asyncnotifier_unittest.py
test/ganeti.daemon_unittest.py

index 51b3a82..d296416 100755 (executable)
@@ -46,9 +46,7 @@ class _MyErrorLoggingAsyncNotifier(asyncnotifier.ErrorLoggingAsyncNotifier):
 
   def handle_error(self):
     self.error_count += 1
-    # We should also terminate while handling an error, so that any unexpected
-    # error is registered and can be checked.
-    os.kill(os.getpid(), signal.SIGTERM)
+    raise
 
 
 class TestSingleFileEventHandler(testutils.GanetiTestCase):
@@ -144,7 +142,7 @@ class TestSingleFileEventHandler(testutils.GanetiTestCase):
   def testError(self):
     self.ihandler[self.NOTIFIER_ERR].enable()
     utils.WriteFile(self.chk_files[self.NOTIFIER_ERR], data="dummy")
-    self.mainloop.Run()
+    self.assertRaises(errors.GenericError, self.mainloop.Run)
     self.assert_(self.notified[self.NOTIFIER_ERR])
     self.assertEquals(self.notifiers[self.NOTIFIER_ERR].error_count, 1)
     self.assertEquals(self.notifiers[self.NOTIFIER_NORM].error_count, 0)
index 81912ee..143be9d 100755 (executable)
@@ -28,6 +28,7 @@ import socket
 import time
 
 from ganeti import daemon
+from ganeti import errors
 
 import testutils
 
@@ -158,6 +159,7 @@ class _MyAsyncUDPSocket(daemon.AsyncUDPSocket):
 
   def handle_error(self):
     self.error_count += 1
+    raise
 
 
 class TestAsyncUDPSocket(testutils.GanetiTestCase):
@@ -214,6 +216,14 @@ class TestAsyncUDPSocket(testutils.GanetiTestCase):
     self.client.enqueue_send("127.0.0.1", self.port, "p3")
     self.client.enqueue_send("127.0.0.1", self.port, "error")
     self.client.enqueue_send("127.0.0.1", self.port, "terminate")
+    self.assertRaises(errors.GenericError, self.mainloop.Run)
+    self.assertEquals(self.server.received,
+                      ["p1", "p2", "error"])
+    self.assertEquals(self.server.error_count, 1)
+    self.assertRaises(errors.GenericError, self.mainloop.Run)
+    self.assertEquals(self.server.received,
+                      ["p1", "p2", "error", "p3", "error"])
+    self.assertEquals(self.server.error_count, 2)
     self.mainloop.Run()
     self.assertEquals(self.server.received,
                       ["p1", "p2", "error", "p3", "error", "terminate"])