Found yet another case of port hardcoding...it's difficult to see these so I keep coming across new ones.

This commit is contained in:
Ryan Williams
2009-10-01 15:40:46 -07:00
parent 5e7c8591c7
commit 15789fda99
2 changed files with 6 additions and 10 deletions

View File

@@ -27,10 +27,8 @@ import unittest
from eventlet.green import urllib2, BaseHTTPServer from eventlet.green import urllib2, BaseHTTPServer
from eventlet.api import spawn, kill from eventlet.api import spawn, kill
port = 18341
def start_http_server(): def start_http_server():
server_address = ('', port) server_address = ('localhost', 0)
BaseHTTPServer.BaseHTTPRequestHandler.protocol_version = "HTTP/1.0" BaseHTTPServer.BaseHTTPRequestHandler.protocol_version = "HTTP/1.0"
httpd = BaseHTTPServer.HTTPServer(server_address, BaseHTTPServer.BaseHTTPRequestHandler) httpd = BaseHTTPServer.HTTPServer(server_address, BaseHTTPServer.BaseHTTPRequestHandler)
sa = httpd.socket.getsockname() sa = httpd.socket.getsockname()
@@ -39,12 +37,12 @@ def start_http_server():
def serve(): def serve():
httpd.handle_request() httpd.handle_request()
httpd.request_count += 1 httpd.request_count += 1
return spawn(serve), httpd return spawn(serve), httpd, sa[1]
class TestGreenness(unittest.TestCase): class TestGreenness(unittest.TestCase):
def setUp(self): def setUp(self):
self.gthread, self.server = start_http_server() self.gthread, self.server,self.port = start_http_server()
#print 'Spawned the server' #print 'Spawned the server'
def tearDown(self): def tearDown(self):
@@ -54,7 +52,7 @@ class TestGreenness(unittest.TestCase):
def test_urllib2(self): def test_urllib2(self):
self.assertEqual(self.server.request_count, 0) self.assertEqual(self.server.request_count, 0)
try: try:
urllib2.urlopen('http://127.0.0.1:%s' % port) urllib2.urlopen('http://127.0.0.1:%s' % self.port)
assert False, 'should not get there' assert False, 'should not get there'
except urllib2.HTTPError, ex: except urllib2.HTTPError, ex:
assert ex.code == 501, `ex` assert ex.code == 501, `ex`

View File

@@ -399,14 +399,12 @@ class TestHttpd(LimitedTestCase):
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt') certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key') private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
port = 4204 sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
sock = api.ssl_listener(('', port), certificate_file, private_key_file)
from eventlet import coros from eventlet import coros
server_coro = coros.execute(server, sock, wsgi_app) server_coro = coros.execute(server, sock, wsgi_app)
client = api.connect_tcp(('127.0.0.1', port)) client = api.connect_tcp(('localhost', sock.getsockname()[1]))
client = util.wrap_ssl(client) client = util.wrap_ssl(client)
client.write('X') # non-empty payload so that SSL handshake occurs client.write('X') # non-empty payload so that SSL handshake occurs
client.shutdown() client.shutdown()