From e3cc4c69bb06ce7e6cff364f6273f0a0db333af2 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Wed, 26 May 2010 14:12:19 +0100
Subject: [PATCH] reraise exceptions in async tests' error handlers

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 |  6 ++----
 test/ganeti.daemon_unittest.py        | 10 ++++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/test/ganeti.asyncnotifier_unittest.py b/test/ganeti.asyncnotifier_unittest.py
index 51b3a82c4..d29641687 100755
--- a/test/ganeti.asyncnotifier_unittest.py
+++ b/test/ganeti.asyncnotifier_unittest.py
@@ -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)
diff --git a/test/ganeti.daemon_unittest.py b/test/ganeti.daemon_unittest.py
index 81912ee18..143be9d4c 100755
--- a/test/ganeti.daemon_unittest.py
+++ b/test/ganeti.daemon_unittest.py
@@ -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"])
-- 
GitLab