Commit b4aca9f5 authored by Jason Madden's avatar Jason Madden

Test tweaks for CI.

parent 4d2f9efd
......@@ -92,6 +92,7 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
except error:
if sock is not None:
sock.close()
sock = None
if res is addrs[-1]:
raise
# without exc_clear(), if connect() fails once, the socket
......@@ -113,6 +114,7 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
# close the socket
if sock is not None:
sock.close()
sock = None
raise
else:
return sock
......
......@@ -403,6 +403,7 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
if hasattr(self, 'cleanup'):
self.cleanup()
self._error = self._none
# XXX: Should probably reverse this
for x in self.close_on_teardown:
close = getattr(x, 'close', x)
try:
......
......@@ -383,6 +383,7 @@ class TestPoolSpawn(TestDefaultSpawn):
return 2
@greentest.skipOnAppVeyor("Connection timeouts are flaky")
@greentest.skipOnPyPy3OnCI("Doesn't always raise timeout for some reason")
def test_pool_full(self):
self.init_server()
short_request = self.send_request('/short')
......
......@@ -322,7 +322,7 @@ def get_port():
class TestCreateConnection(greentest.TestCase):
__timeout__ = 5000
__timeout__ = 5
def test_refuses(self):
with self.assertRaises(socket.error) as cm:
......
......@@ -10,26 +10,33 @@ class Test(greentest.TestCase):
server_port = None
def _accept(self):
conn, _ = self.server.accept()
self._close_on_teardown(conn)
self.server.listen(1)
try:
conn, _ = self.server.accept()
self._close_on_teardown(conn)
except socket.error:
pass
def setUp(self):
super(Test, self).setUp()
self.server = socket.socket()
self._close_on_teardown(self.server)
self.server.bind(('127.0.0.1', 0))
self.server.listen(1)
self.server_port = self.server.getsockname()[1]
self.acceptor = gevent.spawn(self._accept)
gevent.sleep(0)
def tearDown(self):
self.acceptor.kill()
self.server.close()
del self.acceptor
del self.server
if self.acceptor is not None:
self.acceptor.kill()
self.acceptor = None
if self.server is not None:
self.server.close()
self.server = None
super(Test, self).tearDown()
def test(self):
def test_timeout(self):
gevent.sleep(0)
sock = socket.socket()
self._close_on_teardown(sock)
sock.connect(('127.0.0.1', self.server_port))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment