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