Upgraded wsgi tests. Reversed logic in hub's exception squelching so it's correct. Re-raising exceptions in greenthread objects so that they pass the test. Now debug.hub_exceptions should be set to True before running if you want to see exceptions on stderr.
This commit is contained in:
@@ -199,6 +199,7 @@ class GreenThread(greenlet.greenlet):
|
|||||||
# ca and ckw are the curried function arguments
|
# ca and ckw are the curried function arguments
|
||||||
for f, ca, ckw in getattr(self, '_exit_funcs', []):
|
for f, ca, ckw in getattr(self, '_exit_funcs', []):
|
||||||
f(exc=sys.exc_info(), *ca, **ckw)
|
f(exc=sys.exc_info(), *ca, **ckw)
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
self._exit_event.send(result)
|
self._exit_event.send(result)
|
||||||
for f, ca, ckw in getattr(self, '_exit_funcs', []):
|
for f, ca, ckw in getattr(self, '_exit_funcs', []):
|
||||||
|
@@ -312,6 +312,6 @@ class BaseHub(object):
|
|||||||
|
|
||||||
def set_timer_exceptions(self, value):
|
def set_timer_exceptions(self, value):
|
||||||
if value:
|
if value:
|
||||||
self.squelch_timer_exception = self._silent_squelch_timer_exception
|
|
||||||
else:
|
|
||||||
self.squelch_timer_exception = self._debug_squelch_timer_exception
|
self.squelch_timer_exception = self._debug_squelch_timer_exception
|
||||||
|
else:
|
||||||
|
self.squelch_timer_exception = self._silent_squelch_timer_exception
|
||||||
|
@@ -536,15 +536,14 @@ class TestHttpd(LimitedTestCase):
|
|||||||
def test_socket_remains_open(self):
|
def test_socket_remains_open(self):
|
||||||
api.kill(self.killer)
|
api.kill(self.killer)
|
||||||
server_sock = api.tcp_listener(('localhost', 0))
|
server_sock = api.tcp_listener(('localhost', 0))
|
||||||
self.port = server_sock.getsockname()[1]
|
|
||||||
server_sock_2 = server_sock.dup()
|
server_sock_2 = server_sock.dup()
|
||||||
self.killer = api.spawn(wsgi.server, server_sock_2, hello_world,
|
self.spawn_server(sock=server_sock_2)
|
||||||
log=self.logfile)
|
|
||||||
# do a single req/response to verify it's up
|
# do a single req/response to verify it's up
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = api.connect_tcp(('localhost', self.port))
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
result = fd.read()
|
fd.flush()
|
||||||
|
result = fd.read(1024)
|
||||||
fd.close()
|
fd.close()
|
||||||
self.assert_(result.startswith('HTTP'), result)
|
self.assert_(result.startswith('HTTP'), result)
|
||||||
self.assert_(result.endswith('hello world'))
|
self.assert_(result.endswith('hello world'))
|
||||||
@@ -552,17 +551,18 @@ class TestHttpd(LimitedTestCase):
|
|||||||
# shut down the server and verify the server_socket fd is still open,
|
# shut down the server and verify the server_socket fd is still open,
|
||||||
# but the actual socketobject passed in to wsgi.server is closed
|
# but the actual socketobject passed in to wsgi.server is closed
|
||||||
api.kill(self.killer)
|
api.kill(self.killer)
|
||||||
api.sleep(0.01)
|
api.sleep(0.001) # make the kill go through
|
||||||
try:
|
try:
|
||||||
server_sock_2.accept()
|
server_sock_2.accept()
|
||||||
|
# shouldn't be able to use this one anymore
|
||||||
except socket.error, exc:
|
except socket.error, exc:
|
||||||
self.assertEqual(exc[0], errno.EBADF)
|
self.assertEqual(exc[0], errno.EBADF)
|
||||||
self.killer = api.spawn(wsgi.server, server_sock, hello_world,
|
self.spawn_server(sock=server_sock)
|
||||||
log=self.logfile)
|
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = api.connect_tcp(('localhost', self.port))
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
result = fd.read()
|
fd.flush()
|
||||||
|
result = fd.read(1024)
|
||||||
fd.close()
|
fd.close()
|
||||||
self.assert_(result.startswith('HTTP'), result)
|
self.assert_(result.startswith('HTTP'), result)
|
||||||
self.assert_(result.endswith('hello world'))
|
self.assert_(result.endswith('hello world'))
|
||||||
@@ -658,17 +658,13 @@ class TestHttpd(LimitedTestCase):
|
|||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def test_025_accept_errors(self):
|
def test_025_accept_errors(self):
|
||||||
api.kill(self.killer)
|
from eventlet import debug
|
||||||
|
debug.hub_exceptions(True)
|
||||||
listener = greensocket.socket()
|
listener = greensocket.socket()
|
||||||
listener.bind(('localhost', 0))
|
listener.bind(('localhost', 0))
|
||||||
# NOT calling listen, to trigger the error
|
# NOT calling listen, to trigger the error
|
||||||
self.port = listener.getsockname()[1]
|
self.logfile = StringIO()
|
||||||
self.killer = api.spawn(
|
self.spawn_server(sock=listener)
|
||||||
wsgi.server,
|
|
||||||
listener,
|
|
||||||
self.site,
|
|
||||||
max_size=128,
|
|
||||||
log=self.logfile)
|
|
||||||
old_stderr = sys.stderr
|
old_stderr = sys.stderr
|
||||||
try:
|
try:
|
||||||
sys.stderr = self.logfile
|
sys.stderr = self.logfile
|
||||||
@@ -683,6 +679,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
self.logfile.getvalue())
|
self.logfile.getvalue())
|
||||||
finally:
|
finally:
|
||||||
sys.stderr = old_stderr
|
sys.stderr = old_stderr
|
||||||
|
debug.hub_exceptions(False)
|
||||||
|
|
||||||
def test_026_log_format(self):
|
def test_026_log_format(self):
|
||||||
self.spawn_server(log_format="HI %(request_line)s HI")
|
self.spawn_server(log_format="HI %(request_line)s HI")
|
||||||
|
Reference in New Issue
Block a user