Commit b6d41b3c authored by Denis Bilenko's avatar Denis Bilenko

test__refcount.py: fixed not to depend on a specific port number

parent 25f52b08
......@@ -38,15 +38,13 @@ from gevent.socket import _original_socket
class Socket(_original_socket):
"Something we can have a weakref to"
address = ('0.0.0.0', 7878)
SOCKET_TIMEOUT = 0.1
def init_server():
s = socket.socket(Socket())
s.settimeout(SOCKET_TIMEOUT)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(address)
s.bind(('127.0.0.1', 0))
s.listen(5)
return s
......@@ -67,10 +65,10 @@ def handle_request(s, raise_on_timeout):
#print 'handle_request - conn refcount: %s' % sys.getrefcount(conn)
#conn.close()
def make_request():
def make_request(port):
#print 'make_request'
s = socket.socket(Socket())
s.connect(address)
s.connect(('127.0.0.1', port))
#print 'make_request - connected'
res = s.send('hello')
#print 'make_request - sent %s' % res
......@@ -83,7 +81,8 @@ def run_interaction(run_client):
s = init_server()
start_new_thread(handle_request, (s, run_client))
if run_client:
start_new_thread(make_request, ())
port = s.getsockname()[1]
start_new_thread(make_request, (port, ))
sleep(0.1+SOCKET_TIMEOUT)
#print sys.getrefcount(s.fd)
#s.close()
......
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