It turns out that if my --eventlet-hub=foo command fails to import foo, I don't really want it to just write a warning, I want it to crash hard. Skipped the threading-related tests when using the libevent hub, as well as the multiple readers test, because it fails all of them.

This commit is contained in:
Ryan Williams
2009-08-31 20:29:11 -07:00
parent 8701415945
commit 8cae3ef448
4 changed files with 29 additions and 8 deletions

View File

@@ -67,6 +67,14 @@ def requires_twisted(func):
return skip_unless_requirement(requirement)(func) return skip_unless_requirement(requirement)(func)
def skip_with_libevent(func):
""" Decorator that skips a test if we're using the libevent hub."""
def requirement(_f):
from eventlet.api import get_hub
return not('libevent' in type(get_hub()).__module__)
return skip_unless_requirement(requirement)(func)
class TestIsTakingTooLong(Exception): class TestIsTakingTooLong(Exception):
""" Custom exception class to be raised when a test's runtime exceeds a limit. """ """ Custom exception class to be raised when a test's runtime exceeds a limit. """
pass pass

View File

@@ -28,15 +28,11 @@ class EventletHub(Plugin):
" specified, the default hub for the current configuration is printed "\ " specified, the default hub for the current configuration is printed "\
" and used." " and used."
def beforeContext(self): def beforeContext(self):
"""Select the desired hub. """Select the desired hub.
""" """
if self.hub_name is None: if self.hub_name is None:
log.warn('using *default* eventlet hub: %s', api.get_hub()) log.warn('using *default* eventlet hub: %s', api.get_hub())
else: else:
try: api.use_hub(self.hub_name)
api.use_hub(self.hub_name) log.info('using hub %s', api.get_hub())
log.info('using hub %s', api.get_hub())
except ImportError, ex:
log.exception('eventlet hub %s not importing', self.hub_name)

View File

@@ -17,7 +17,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from tests import skipped, LimitedTestCase from tests import skipped, LimitedTestCase, skip_with_libevent
from unittest import main from unittest import main
from eventlet import api, util, coros, proc from eventlet import api, util, coros, proc
import os import os
@@ -182,6 +182,7 @@ class TestGreenIo(LimitedTestCase):
for bytes in (1000, 10000, 100000, 1000000): for bytes in (1000, 10000, 100000, 1000000):
test_sendall_impl(bytes) test_sendall_impl(bytes)
@skip_with_libevent
def test_multiple_readers(self): def test_multiple_readers(self):
# test that we can have multiple coroutines reading # test that we can have multiple coroutines reading
# from the same fd. We make no guarantees about which one gets which # from the same fd. We make no guarantees about which one gets which

View File

@@ -16,7 +16,7 @@
import random import random
from sys import stdout from sys import stdout
import time import time
from tests import skipped from tests import skipped, skip_with_libevent
from unittest import TestCase, main from unittest import TestCase, main
import uuid import uuid
@@ -70,6 +70,7 @@ class TestTpool(TestCase):
tpool.QUIET = False tpool.QUIET = False
tpool.killall() tpool.killall()
@skip_with_libevent
def test_a_buncha_stuff(self): def test_a_buncha_stuff(self):
pool = coros.CoroutinePool(max_size=10) pool = coros.CoroutinePool(max_size=10)
waiters = [] waiters = []
@@ -78,6 +79,7 @@ class TestTpool(TestCase):
for waiter in waiters: for waiter in waiters:
waiter.wait() waiter.wait()
@skip_with_libevent
def test_wrap_tuple(self): def test_wrap_tuple(self):
my_tuple = (1, 2) my_tuple = (1, 2)
prox = tpool.Proxy(my_tuple) prox = tpool.Proxy(my_tuple)
@@ -85,6 +87,7 @@ class TestTpool(TestCase):
self.assertEqual(prox[1], 2) self.assertEqual(prox[1], 2)
self.assertEqual(len(my_tuple), 2) self.assertEqual(len(my_tuple), 2)
@skip_with_libevent
def test_wrap_string(self): def test_wrap_string(self):
my_object = "whatever" my_object = "whatever"
prox = tpool.Proxy(my_object) prox = tpool.Proxy(my_object)
@@ -92,6 +95,7 @@ class TestTpool(TestCase):
self.assertEqual(len(my_object), len(prox)) self.assertEqual(len(my_object), len(prox))
self.assertEqual(my_object.join(['a', 'b']), prox.join(['a', 'b'])) self.assertEqual(my_object.join(['a', 'b']), prox.join(['a', 'b']))
@skip_with_libevent
def test_wrap_uniterable(self): def test_wrap_uniterable(self):
# here we're treating the exception as just a normal class # here we're treating the exception as just a normal class
prox = tpool.Proxy(FloatingPointError()) prox = tpool.Proxy(FloatingPointError())
@@ -103,6 +107,7 @@ class TestTpool(TestCase):
self.assertRaises(IndexError, index) self.assertRaises(IndexError, index)
self.assertRaises(TypeError, key) self.assertRaises(TypeError, key)
@skip_with_libevent
def test_wrap_dict(self): def test_wrap_dict(self):
my_object = {'a':1} my_object = {'a':1}
prox = tpool.Proxy(my_object) prox = tpool.Proxy(my_object)
@@ -112,6 +117,7 @@ class TestTpool(TestCase):
self.assertEqual(repr(my_object), repr(prox)) self.assertEqual(repr(my_object), repr(prox))
self.assertEqual(`my_object`, `prox`) self.assertEqual(`my_object`, `prox`)
@skip_with_libevent
def test_wrap_module_class(self): def test_wrap_module_class(self):
prox = tpool.Proxy(uuid) prox = tpool.Proxy(uuid)
self.assertEqual(tpool.Proxy, type(prox)) self.assertEqual(tpool.Proxy, type(prox))
@@ -119,6 +125,7 @@ class TestTpool(TestCase):
self.assertEqual(id.get_version(), uuid.uuid4().get_version()) self.assertEqual(id.get_version(), uuid.uuid4().get_version())
self.assert_(repr(prox.uuid4)) self.assert_(repr(prox.uuid4))
@skip_with_libevent
def test_wrap_eq(self): def test_wrap_eq(self):
prox = tpool.Proxy(uuid) prox = tpool.Proxy(uuid)
id1 = prox.uuid4() id1 = prox.uuid4()
@@ -127,6 +134,7 @@ class TestTpool(TestCase):
id3 = prox.uuid4() id3 = prox.uuid4()
self.assert_(id1 != id3) self.assert_(id1 != id3)
@skip_with_libevent
def test_wrap_nonzero(self): def test_wrap_nonzero(self):
prox = tpool.Proxy(uuid) prox = tpool.Proxy(uuid)
id1 = prox.uuid4() id1 = prox.uuid4()
@@ -134,6 +142,7 @@ class TestTpool(TestCase):
prox2 = tpool.Proxy([1, 2, 3]) prox2 = tpool.Proxy([1, 2, 3])
self.assert_(bool(prox2)) self.assert_(bool(prox2))
@skip_with_libevent
def test_multiple_wraps(self): def test_multiple_wraps(self):
prox1 = tpool.Proxy(uuid) prox1 = tpool.Proxy(uuid)
prox2 = tpool.Proxy(uuid) prox2 = tpool.Proxy(uuid)
@@ -142,15 +151,18 @@ class TestTpool(TestCase):
del x2 del x2
x3 = prox2.uuid4() x3 = prox2.uuid4()
@skip_with_libevent
def test_wrap_getitem(self): def test_wrap_getitem(self):
prox = tpool.Proxy([0,1,2]) prox = tpool.Proxy([0,1,2])
self.assertEqual(prox[0], 0) self.assertEqual(prox[0], 0)
@skip_with_libevent
def test_wrap_setitem(self): def test_wrap_setitem(self):
prox = tpool.Proxy([0,1,2]) prox = tpool.Proxy([0,1,2])
prox[1] = 2 prox[1] = 2
self.assertEqual(prox[1], 2) self.assertEqual(prox[1], 2)
@skip_with_libevent
def test_raising_exceptions(self): def test_raising_exceptions(self):
prox = tpool.Proxy(uuid) prox = tpool.Proxy(uuid)
def nofunc(): def nofunc():
@@ -160,6 +172,7 @@ class TestTpool(TestCase):
def assertLessThan(self, a, b): def assertLessThan(self, a, b):
self.assert_(a < b, "%s is not less than %s" % (a, b)) self.assert_(a < b, "%s is not less than %s" % (a, b))
@skip_with_libevent
def test_variable_and_keyword_arguments_with_function_calls(self): def test_variable_and_keyword_arguments_with_function_calls(self):
import optparse import optparse
parser = tpool.Proxy(optparse.OptionParser()) parser = tpool.Proxy(optparse.OptionParser())
@@ -167,6 +180,7 @@ class TestTpool(TestCase):
opts,args = parser.parse_args(["-nfoo"]) opts,args = parser.parse_args(["-nfoo"])
self.assertEqual(opts.n, 'foo') self.assertEqual(opts.n, 'foo')
@skip_with_libevent
def test_contention(self): def test_contention(self):
from tests import tpool_test from tests import tpool_test
prox = tpool.Proxy(tpool_test) prox = tpool.Proxy(tpool_test)
@@ -179,12 +193,14 @@ class TestTpool(TestCase):
for waiter in waiters: for waiter in waiters:
waiter.wait() waiter.wait()
@skip_with_libevent
def test_timeout(self): def test_timeout(self):
import time import time
api.exc_after(0.1, api.TimeoutError()) api.exc_after(0.1, api.TimeoutError())
self.assertRaises(api.TimeoutError, self.assertRaises(api.TimeoutError,
tpool.execute, time.sleep, 0.3) tpool.execute, time.sleep, 0.3)
@skip_with_libevent
def test_killall(self): def test_killall(self):
tpool.killall() tpool.killall()
tpool.setup() tpool.setup()