This commit is contained in:
Ryan Williams
2010-02-22 17:04:44 -05:00
5 changed files with 122 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ debugging Eventlet-powered applications."""
import os
import sys
import linecache
import string
import inspect
__all__ = ['spew', 'unspew', 'format_hub_listeners', 'hub_listener_stacks',
'hub_exceptions', 'tpool_exceptions']
@@ -122,4 +124,4 @@ def tpool_exceptions(state):
functions that are executed in it, in addition to raising them like
it normally does."""
from eventlet import tpool
tpool.QUIET = not state
tpool.QUIET = not state

View File

@@ -181,6 +181,15 @@ class LightQueue(object):
def qsize(self):
"""Return the size of the queue."""
return len(self.queue)
def resize(self, size):
"""Resizes the queue's maximum size.
If the size is increased, and there are putters waiting, they may be woken up."""
if size > self.maxsize:
# Maybe wake some stuff up
self._schedule_unlock()
self.maxsize = size
def putting(self):
"""Returns the number of greenthreads that are blocked waiting to put

View File

@@ -4,6 +4,7 @@ try:
GreenletExit = greenlet.GreenletExit
greenlet = greenlet.greenlet
except ImportError, e:
raise
try:
from py.magic import greenlet
getcurrent = greenlet.getcurrent

View File

@@ -4,12 +4,90 @@ import eventlet
from eventlet import debug
from eventlet import api
from tests import LimitedTestCase, main
from unittest import TestCase
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
class TestSpew(TestCase):
def setUp(self):
self.orig_trace = sys.settrace
sys.settrace = self._settrace
self.tracer = None
def tearDown(self):
sys.settrace = self.orig_trace
sys.stdout = sys.__stdout__
def _settrace(self, cb):
self.tracer = cb
def test_spew(self):
debug.spew()
self.failUnless(isinstance(self.tracer, debug.Spew))
def test_unspew(self):
debug.spew()
debug.unspew()
self.failUnlessEqual(self.tracer, None)
def test_line(self):
sys.stdout = StringIO()
s = debug.Spew()
f = sys._getframe()
s(f, "line", None)
lineno = f.f_lineno - 1 # -1 here since we called with frame f in the line above
output = sys.stdout.getvalue()
self.failUnless("debug_test:%i" % lineno in output, "Didn't find line %i in %s" % (lineno, output))
self.failUnless("f=<frame object at" in output)
def test_line_nofile(self):
sys.stdout = StringIO()
s = debug.Spew()
g = globals().copy()
del g['__file__']
f = eval("sys._getframe()", g)
s(f, "line", None)
output = sys.stdout.getvalue()
self.failUnless("[unknown]:1" in output, "Didn't find [unknown]:1 in %s" % (output))
self.failUnless("VM instruction #" in output, output)
def test_line_global(self):
global GLOBAL_VAR
sys.stdout = StringIO()
GLOBAL_VAR = debug.Spew()
f = sys._getframe()
GLOBAL_VAR(f, "line", None)
lineno = f.f_lineno - 1 # -1 here since we called with frame f in the line above
output = sys.stdout.getvalue()
self.failUnless("debug_test:%i" % lineno in output, "Didn't find line %i in %s" % (lineno, output))
self.failUnless("f=<frame object at" in output)
self.failUnless("GLOBAL_VAR" in f.f_globals)
self.failUnless("GLOBAL_VAR=<eventlet.debug.Spew object at" in output)
del GLOBAL_VAR
def test_line_novalue(self):
sys.stdout = StringIO()
s = debug.Spew(show_values=False)
f = sys._getframe()
s(f, "line", None)
lineno = f.f_lineno - 1 # -1 here since we called with frame f in the line above
output = sys.stdout.getvalue()
self.failUnless("debug_test:%i" % lineno in output, "Didn't find line %i in %s" % (lineno, output))
self.failIf("f=<frame object at" in output)
def test_line_nooutput(self):
sys.stdout = StringIO()
s = debug.Spew(trace_names=['foo'])
f = sys._getframe()
s(f, "line", None)
lineno = f.f_lineno - 1 # -1 here since we called with frame f in the line above
output = sys.stdout.getvalue()
self.failUnlessEqual(output, "")
class TestDebug(LimitedTestCase):
def test_everything(self):
debug.hub_exceptions(True)
@@ -18,7 +96,10 @@ class TestDebug(LimitedTestCase):
debug.tpool_exceptions(False)
debug.hub_listener_stacks(True)
debug.hub_listener_stacks(False)
debug.hub_timer_stacks(True)
debug.hub_timer_stacks(False)
debug.format_hub_listeners()
debug.format_hub_timers()
def test_hub_exceptions(self):
debug.hub_exceptions(True)
@@ -46,4 +127,4 @@ class TestDebug(LimitedTestCase):
"Traceback not in:\n" + fake.getvalue())
if __name__ == "__main__":
main()
main()

View File

@@ -68,6 +68,33 @@ class TestQueue(LimitedTestCase):
self.assertEquals(evt.wait(),'done')
gt.wait()
def test_resize_up(self):
q = eventlet.Queue(0)
def sender(evt, q):
q.put('hi')
evt.send('done')
evt = event.Event()
gt = eventlet.spawn(sender, evt, q)
eventlet.sleep(0)
self.assert_(not evt.ready())
q.resize(1)
eventlet.sleep(0)
self.assert_(evt.ready())
gt.wait()
def test_resize_down(self):
size = 5
q = eventlet.Queue(5)
for i in range(5):
q.put(i)
self.assertEquals(list(q.queue), range(5))
q.resize(1)
eventlet.sleep(0)
self.assertEquals(list(q.queue), range(5))
def test_multiple_waiters(self):
# tests that multiple waiters get their results back
q = eventlet.Queue()