Finally, some peace and quiet around here. :-)

This commit is contained in:
Ryan Williams
2009-12-06 19:20:45 -08:00
parent 5db1ed5f59
commit 15d4bc723b
5 changed files with 33 additions and 23 deletions

View File

@@ -61,6 +61,7 @@ class BaseHub(object):
'exit': [],
}
self.lclass = FdListener
self.silent_timer_exceptions = False
def add(self, evtype, fileno, cb):
""" Signals an intent to or write a particular file descriptor.
@@ -220,8 +221,9 @@ class BaseHub(object):
self.squelch_observer_exception(observer, sys.exc_info())
def squelch_timer_exception(self, timer, exc_info):
traceback.print_exception(*exc_info)
print >>sys.stderr, "Timer raised: %r" % (timer,)
if not self.silent_timer_exceptions:
traceback.print_exception(*exc_info)
print >>sys.stderr, "Timer raised: %r" % (timer,)
def _add_absolute_timer(self, when, info):
# the 0 placeholder makes it easy to bisect_right using (now, 1)

View File

@@ -82,6 +82,20 @@ class LimitedTestCase(unittest.TestCase):
self.timer.cancel()
class SilencedTestCase(LimitedTestCase):
""" Subclass of LimitedTestCase that also silences the printing of timer
exceptions."""
def setUp(self):
from eventlet import api
super(SilencedTestCase, self).setUp()
api.get_hub().silent_timer_exceptions = True
def tearDown(self):
from eventlet import api
super(SilencedTestCase, self).tearDown()
api.get_hub().silent_timer_exceptions = False
def find_command(command):
for dir in os.getenv('PATH', '/usr/bin:/usr/sbin').split(os.pathsep):
p = os.path.join(dir, command)

View File

@@ -1,15 +1,8 @@
from unittest import TestCase, main
from unittest import main, TestCase
from tests import SilencedTestCase
from eventlet import coros, api
class TestEvent(TestCase):
mode = 'static'
def setUp(self):
# raise an exception if we're waiting forever
self._cancel_timeout = api.exc_after(1, RuntimeError('test takes too long'))
def tearDown(self):
self._cancel_timeout.cancel()
class TestEvent(SilencedTestCase):
def test_waiting_for_event(self):
evt = coros.event()
value = 'some stuff'
@@ -81,15 +74,14 @@ class IncrActor(coros.Actor):
if evt: evt.send()
class TestActor(TestCase):
class TestActor(SilencedTestCase):
mode = 'static'
def setUp(self):
# raise an exception if we're waiting forever
self._cancel_timeout = api.exc_after(1, api.TimeoutError())
super(TestActor, self).setUp()
self.actor = IncrActor()
def tearDown(self):
self._cancel_timeout.cancel()
super(TestActor, self).tearDown()
api.kill(self.actor._killer)
def test_cast(self):

View File

@@ -1,4 +1,5 @@
import unittest
from tests import SilencedTestCase
import time
from eventlet import api
from eventlet.green import socket
@@ -29,7 +30,7 @@ class TestDebug(unittest.TestCase):
self.assert_(not api.get_hub().debug)
class TestExceptionInMainloop(unittest.TestCase):
class TestExceptionInMainloop(SilencedTestCase):
def test_sleep(self):
# even if there was an error in the mainloop, the hub should continue to work

View File

@@ -2,14 +2,14 @@ import sys
import unittest
from eventlet.api import sleep, with_timeout
from eventlet import api, proc, coros
from tests import LimitedTestCase, skipped
from tests import SilencedTestCase, skipped
DELAY = 0.01
class ExpectedError(Exception):
pass
class TestLink_Signal(LimitedTestCase):
class TestLink_Signal(SilencedTestCase):
def test_send(self):
s = proc.Source()
@@ -48,7 +48,7 @@ class TestLink_Signal(LimitedTestCase):
self.assertRaises(OSError, s.wait)
class TestProc(LimitedTestCase):
class TestProc(SilencedTestCase):
def test_proc(self):
p = proc.spawn(lambda : 100)
@@ -76,13 +76,13 @@ class TestProc(LimitedTestCase):
self.assertRaises(proc.LinkedCompleted, sleep, 0.1)
class TestCase(LimitedTestCase):
class TestCase(SilencedTestCase):
def link(self, p, listener=None):
getattr(p, self.link_method)(listener)
def tearDown(self):
LimitedTestCase.tearDown(self)
SilencedTestCase.tearDown(self)
self.p.unlink()
def set_links(self, p, first_time, kill_exc_type):
@@ -252,7 +252,7 @@ class TestRaise_link_exception(TestRaise_link):
link_method = 'link_exception'
class TestStuff(unittest.TestCase):
class TestStuff(SilencedTestCase):
def test_wait_noerrors(self):
x = proc.spawn(lambda : 1)
@@ -297,6 +297,7 @@ class TestStuff(unittest.TestCase):
proc.waitall([a, b])
except ExpectedError, ex:
assert 'second' in str(ex), repr(str(ex))
api.sleep(0.2) # sleep to ensure that the other timer is raised
def test_multiple_listeners_error(self):
# if there was an error while calling a callback