Skip to content

Commit

Permalink
fix port value mismatch in create_server
Browse files Browse the repository at this point in the history
  • Loading branch information
claws authored and 1st1 committed May 4, 2016
1 parent dca023d commit f27f985
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,32 @@ def test_create_server_2(self):
with self.assertRaisesRegex(ValueError, 'nor sock were specified'):
self.loop.run_until_complete(self.loop.create_server(object))

def test_create_server_3(self):
''' check ephemeral port can be used '''

async def start_server_ephemeral_ports():

for port_sentinel in [0, None]:
srv = await self.loop.create_server(
asyncio.Protocol,
'127.0.0.1', port_sentinel,
family=socket.AF_INET)

srv_socks = srv.sockets
self.assertTrue(srv_socks)

host, port = srv_socks[0].getsockname()
self.assertNotEqual(0, port)

self.loop.call_soon(srv.close)
await srv.wait_closed()

# Check that the server cleaned-up proxy-sockets
for srv_sock in srv_socks:
self.assertEqual(srv_sock.fileno(), -1)

self.loop.run_until_complete(start_server_ephemeral_ports())

def test_create_connection_1(self):
CNT = 0
TOTAL_CNT = 100
Expand Down
2 changes: 2 additions & 0 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ cdef class Loop:
int proto, int flags,
int unpack):

if port is None:
port = 0
if isinstance(port, str):
port = port.encode()
elif isinstance(port, int):
Expand Down

0 comments on commit f27f985

Please sign in to comment.