Skip to content

Commit

Permalink
[tests] let the OS pick a free port on which to bind test server
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed Mar 10, 2021
1 parent aaf8305 commit b01aeed
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ async def serve():

class HighLevelTest(TestCase):
def setUp(self):
self.bogus_port = 1024
self.server = None
self.server_host = "localhost"
self.server_port = 4433
self.server_port = 0

def tearDown(self):
if self.server is not None:
Expand Down Expand Up @@ -105,11 +106,12 @@ async def run_server(self, configuration=None, host="::", **kwargs):
configuration.load_cert_chain(SERVER_CERTFILE, SERVER_KEYFILE)
self.server = await serve(
host=host,
port=self.server_port,
port=0,
configuration=configuration,
stream_handler=handle_stream,
**kwargs
)
self.server_port = self.server._transport.get_extra_info("sockname")[1]
return self.server

def test_connect_and_serve(self):
Expand Down Expand Up @@ -306,7 +308,7 @@ def test_connect_timeout(self):
with self.assertRaises(ConnectionError):
run(
self.run_client(
port=4400,
port=self.bogus_port,
configuration=QuicConfiguration(is_client=True, idle_timeout=5),
)
)
Expand All @@ -316,7 +318,7 @@ async def run_client_no_wait_connected(configuration):
configuration.load_verify_locations(cafile=SERVER_CACERTFILE)
async with connect(
self.server_host,
4400,
self.bogus_port,
configuration=configuration,
wait_connected=False,
) as client:
Expand Down

0 comments on commit b01aeed

Please sign in to comment.