Skip to content
Snippets Groups Projects
Commit e3cc4c69 authored by Guido Trotter's avatar Guido Trotter
Browse files

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 37e1e262
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment