Commit ef56bb00 authored by Jason Madden's avatar Jason Madden

Use 127.0.0.1 instead of '' to bind on Travis because of errno 99.

parent 69bf8aea
......@@ -371,6 +371,7 @@ LOCAL_TIMEOUT = 1
DEFAULT_LOCAL_HOST_ADDR = 'localhost'
DEFAULT_LOCAL_HOST_ADDR6 = DEFAULT_LOCAL_HOST_ADDR
DEFAULT_BIND_ADDR = ''
if RUNNING_ON_TRAVIS:
# As of November 2017 (probably Sept or Oct), after a
......@@ -380,6 +381,9 @@ if RUNNING_ON_TRAVIS:
# docker containers. Sigh.
DEFAULT_LOCAL_HOST_ADDR = '127.0.0.1'
DEFAULT_LOCAL_HOST_ADDR6 = '::1'
# Likewise, binding to '' appears to work, but it cannot be
# connected to with the same error.
DEFAULT_BIND_ADDR = '127.0.0.1'
class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
__timeout__ = LOCAL_TIMEOUT if not RUNNING_ON_CI else CI_TIMEOUT
......
......@@ -107,7 +107,6 @@ class TestCase(greentest.TestCase):
sock.connect((server_host, server_port))
except Exception:
# avoid ResourceWarning under Py3
print("Failed to connect to", server_host, server_port, self.server.server_host)
sock.close()
raise
......@@ -188,13 +187,13 @@ class TestCase(greentest.TestCase):
self.assertConnectionRefused()
def report_netstat(self, msg):
return
if 0:
print(msg)
os.system('sudo netstat -anp | grep %s' % os.getpid())
print('^^^^^')
def _create_server(self):
return self.ServerSubClass(('', 0))
return self.ServerSubClass((greentest.DEFAULT_BIND_ADDR, 0))
def init_server(self):
self.server = self._create_server()
......@@ -207,7 +206,7 @@ class TestCase(greentest.TestCase):
def _test_invalid_callback(self):
try:
self.server = self.ServerClass(('', 0), lambda: None)
self.server = self.ServerClass((greentest.DEFAULT_BIND_ADDR, 0), lambda: None)
self.server.start()
self.expect_one_error()
......@@ -254,7 +253,7 @@ class TestDefaultSpawn(TestCase):
self.assertRaises(TypeError, self.ServerClass, self.get_listener(), backlog=25, handle=False)
def test_backlog_is_accepted_for_address(self):
self.server = self.ServerSubClass(('', 0), backlog=25)
self.server = self.ServerSubClass((greentest.DEFAULT_BIND_ADDR, 0), backlog=25)
self.assertConnectionRefused()
self._test_server_start_stop(restartable=False)
......@@ -264,12 +263,13 @@ class TestDefaultSpawn(TestCase):
def test_subclass_with_socket(self):
self.server = self.ServerSubClass(self.get_listener())
# the connection won't be refused, because there exists a listening socket, but it won't be handled also
# the connection won't be refused, because there exists a
# listening socket, but it won't be handled also
self.assertNotAccepted()
self._test_server_start_stop(restartable=True)
def test_subclass_with_address(self):
self.server = self.ServerSubClass(('', 0))
self.server = self.ServerSubClass((greentest.DEFAULT_BIND_ADDR, 0))
self.assertConnectionRefused()
self._test_server_start_stop(restartable=True)
......@@ -295,7 +295,7 @@ class TestDefaultSpawn(TestCase):
self._test_serve_forever()
def test_serve_forever_after_start(self):
self.server = self.ServerSubClass(('', 0))
self.server = self.ServerSubClass((greentest.DEFAULT_BIND_ADDR, 0))
self.assertConnectionRefused()
assert not self.server.started
self.server.start()
......@@ -303,7 +303,7 @@ class TestDefaultSpawn(TestCase):
self._test_serve_forever()
def test_server_closes_client_sockets(self):
self.server = self.ServerClass(('', 0), lambda *args: [])
self.server = self.ServerClass((greentest.DEFAULT_BIND_ADDR, 0), lambda *args: [])
self.server.start()
conn = self.send_request()
timeout = gevent.Timeout.start_new(1)
......@@ -422,7 +422,7 @@ class TestNoneSpawn(TestCase):
def test_assertion_in_blocking_func(self):
def sleep(*args):
gevent.sleep(0)
self.server = Settings.ServerClass(('', 0), sleep, spawn=None)
self.server = Settings.ServerClass((greentest.DEFAULT_BIND_ADDR, 0), sleep, spawn=None)
self.server.start()
self.expect_one_error()
self.assert500()
......@@ -461,7 +461,7 @@ else:
class TestSSLGetCertificate(TestCase):
def _create_server(self):
return self.ServerSubClass(('', 0),
return self.ServerSubClass((greentest.DEFAULT_BIND_ADDR, 0),
keyfile=_file('server.key'),
certfile=_file('server.crt'))
......
......@@ -326,7 +326,9 @@ class TestCreateConnection(greentest.TestCase):
def test(self):
try:
socket.create_connection(('localhost', get_port()), timeout=30, source_address=('', get_port()))
socket.create_connection((greentest.DEFAULT_BIND_ADDR, get_port()),
timeout=30,
source_address=('', get_port()))
except socket.error as ex:
if 'refused' not in str(ex).lower():
raise
......
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