Skip to content

Commit

Permalink
test_start_runserver_ssl amendment
Browse files Browse the repository at this point in the history
  • Loading branch information
zrvku2000 committed Feb 3, 2025
1 parent 39dc597 commit ebd2870
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
linux_forked = pytest.mark.forked
else:
def linux_forked(func):
return func
return func

SIMPLE_APP = {
'app.py': """\
Expand Down
14 changes: 7 additions & 7 deletions tests/test_runserver_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,23 @@ async def test_websocket_reload(aux_cli):
await ws.close()


async def check_ssl_server_running(check_callback, sslcontext):
async def check_ssl_server_running(check_callback):
port_open = False
ssl_context = ssl.create_default_context()
ssl_context.load_verify_locations('test_certs/rootCA.pem')

async with aiohttp.ClientSession(timeout=ClientTimeout(total=1)) as session:
for i in range(50): # pragma: no branch
try:
async with session.get('https://localhost:8443/', ssl=sslcontext):
async with session.get('https://localhost:8443/', ssl=ssl_context):
pass
except OSError:
await asyncio.sleep(0.1)
else:
port_open = True
break
assert port_open
await check_callback(session, sslcontext)
await check_callback(session, ssl_context)
await asyncio.sleep(.25) # TODO(aiohttp 4): Remove this hack


Expand Down Expand Up @@ -368,9 +371,6 @@ def get_ssl_context():
for startup in aux_app.on_startup:
loop.run_until_complete(startup(aux_app))

ssl_context = ssl.create_default_context()
ssl_context.load_verify_locations('test_certs/rootCA.pem')

async def check_callback(session, ssl_context):
print(session, ssl_context)
async with session.get('https://localhost:8443/', ssl=ssl_context) as r:
Expand All @@ -386,7 +386,7 @@ async def check_callback(session, ssl_context):
assert 'raise ValueError()' in (await r.text())

try:
loop.run_until_complete(check_ssl_server_running(check_callback, ssl_context))
loop.run_until_complete(check_ssl_server_running(check_callback))
finally:
for shutdown in aux_app.on_shutdown:
loop.run_until_complete(shutdown(aux_app))
Expand Down

0 comments on commit ebd2870

Please sign in to comment.