#44 wsgi_test totally leaving open sockets

- inherited tearDown  should be executed after own teradown.
- Added sleeps to give tasks chance to execute.
- changed deprecated api.sleep to eventlet.sleep
This commit is contained in:
amajorek
2010-03-12 00:47:59 -05:00
parent e153c9207b
commit c07b2bf5e2

View File

@@ -137,9 +137,9 @@ class TestHttpd(LimitedTestCase):
self.spawn_server() self.spawn_server()
def tearDown(self): def tearDown(self):
super(TestHttpd, self).tearDown()
greenthread.kill(self.killer) greenthread.kill(self.killer)
eventlet.sleep(0) eventlet.sleep(0)
super(TestHttpd, self).tearDown()
def spawn_server(self, **kwargs): def spawn_server(self, **kwargs):
"""Spawns a new wsgi server with the given arguments. """Spawns a new wsgi server with the given arguments.
@@ -147,8 +147,10 @@ class TestHttpd(LimitedTestCase):
running it. running it.
Kills any previously-running server.""" Kills any previously-running server."""
eventlet.sleep(0) # give previous server a chance to start
if self.killer: if self.killer:
greenthread.kill(self.killer) greenthread.kill(self.killer)
eventlet.sleep(0) # give killer a chance to kill
new_kwargs = dict(max_size=128, new_kwargs = dict(max_size=128,
log=self.logfile, log=self.logfile,
@@ -252,6 +254,7 @@ class TestHttpd(LimitedTestCase):
a = cgi.parse_qs(body).get('a', [1])[0] a = cgi.parse_qs(body).get('a', [1])[0]
start_response('200 OK', [('Content-type', 'text/plain')]) start_response('200 OK', [('Content-type', 'text/plain')])
return ['a is %s, body is %s' % (a, body)] return ['a is %s, body is %s' % (a, body)]
self.site.application = new_app self.site.application = new_app
sock = eventlet.connect( sock = eventlet.connect(
('localhost', self.port)) ('localhost', self.port))
@@ -559,7 +562,7 @@ 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
greenthread.kill(self.killer) greenthread.kill(self.killer)
api.sleep(0.001) # make the kill go through eventlet.sleep(0) # make the kill go through
try: try:
server_sock_2.accept() server_sock_2.accept()
# shouldn't be able to use this one anymore # shouldn't be able to use this one anymore
@@ -676,7 +679,7 @@ class TestHttpd(LimitedTestCase):
old_stderr = sys.stderr old_stderr = sys.stderr
try: try:
sys.stderr = self.logfile sys.stderr = self.logfile
api.sleep(0) # need to enter server loop eventlet.sleep(0) # need to enter server loop
try: try:
eventlet.connect(('localhost', self.port)) eventlet.connect(('localhost', self.port))
self.fail("Didn't expect to connect") self.fail("Didn't expect to connect")
@@ -758,7 +761,7 @@ class TestHttpd(LimitedTestCase):
client.sendall(data) client.sendall(data)
else: # close sock prematurely else: # close sock prematurely
client.close() client.close()
api.sleep(0) # let context switch back to server eventlet.sleep(0) # let context switch back to server
self.assert_(not errored[0], errored[0]) self.assert_(not errored[0], errored[0])
# make another request to ensure the server's still alive # make another request to ensure the server's still alive
try: try: