Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Tests

on:
# TODO: (Vizonex) Remove later I'm just a little impaitient...
workflow_dispatch:
push:
branches:
- master
- ci
pull_request:
branches:
- windows
- master

jobs:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def build_extensions(self):
"vendor/libuv/src/win",
"vendor/libuv/include",
],
extra_compile_args=["/std:c11", "/experimental:c11atomics"],
# subset of libuv Windows libraries:
extra_link_args=[
(f"-l{lib}" if MINGW else f"{lib}.lib")
Expand Down
2 changes: 1 addition & 1 deletion tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def suite():
return test_suite


if __name__ == '__main__':
if __name__ == "__main__":
runner = unittest.runner.TextTestRunner()
result = runner.run(suite())
sys.exit(not result.wasSuccessful())
33 changes: 17 additions & 16 deletions tests/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@ class _TestAioHTTP:

def test_aiohttp_basic_1(self):

PAYLOAD = '<h1>It Works!</h1>' * 10000
PAYLOAD = "<h1>It Works!</h1>" * 10000

async def on_request(request):
return aiohttp.web.Response(text=PAYLOAD)

asyncio.set_event_loop(self.loop)
app = aiohttp.web.Application()
app.router.add_get('/', on_request)
app.router.add_get("/", on_request)

runner = aiohttp.web.AppRunner(app)
self.loop.run_until_complete(runner.setup())
site = aiohttp.web.TCPSite(runner, '0.0.0.0', '0')
site = aiohttp.web.TCPSite(runner, "0.0.0.0", "0")
self.loop.run_until_complete(site.start())
port = site._server.sockets[0].getsockname()[1]

async def test():
# Make sure we're using the correct event loop.
self.assertIs(asyncio.get_event_loop(), self.loop)

for addr in (('localhost', port),
('127.0.0.1', port)):
for addr in (("localhost", port), ("127.0.0.1", port)):
async with aiohttp.ClientSession() as client:
async with client.get('http://{}:{}'.format(*addr)) as r:
async with client.get("http://{}:{}".format(*addr)) as r:
self.assertEqual(r.status, 200)
result = await r.text()
self.assertEqual(result, PAYLOAD)
Expand All @@ -49,42 +48,43 @@ async def test():
self.loop.run_until_complete(runner.cleanup())

def test_aiohttp_graceful_shutdown(self):
if self.implementation == 'asyncio' and sys.version_info >= (3, 12, 0):
if self.implementation == "asyncio" and sys.version_info >= (3, 12, 0):
# In Python 3.12.0, asyncio.Server.wait_closed() waits for all
# existing connections to complete, before aiohttp sends
# on_shutdown signals.
# https://github.com/aio-libs/aiohttp/issues/7675#issuecomment-1752143748
# https://github.com/python/cpython/pull/98582
raise unittest.SkipTest('bug in aiohttp: #7675')
raise unittest.SkipTest("bug in aiohttp: #7675")

async def websocket_handler(request):
ws = aiohttp.web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].add(ws)
request.app["websockets"].add(ws)
try:
async for msg in ws:
await ws.send_str(msg.data)
finally:
request.app['websockets'].discard(ws)
request.app["websockets"].discard(ws)
return ws

async def on_shutdown(app):
for ws in set(app['websockets']):
for ws in set(app["websockets"]):
await ws.close(
code=aiohttp.WSCloseCode.GOING_AWAY,
message='Server shutdown')
message="Server shutdown",
)

asyncio.set_event_loop(self.loop)
app = aiohttp.web.Application()
app.router.add_get('/', websocket_handler)
app.router.add_get("/", websocket_handler)
app.on_shutdown.append(on_shutdown)
app['websockets'] = weakref.WeakSet()
app["websockets"] = weakref.WeakSet()

runner = aiohttp.web.AppRunner(app)
self.loop.run_until_complete(runner.setup())
site = aiohttp.web.TCPSite(
runner,
'0.0.0.0',
"0.0.0.0",
0,
# https://github.com/aio-libs/aiohttp/pull/7188
shutdown_timeout=0.1,
Expand All @@ -95,7 +95,8 @@ async def on_shutdown(app):
async def client():
async with aiohttp.ClientSession() as client:
async with client.ws_connect(
'http://127.0.0.1:{}'.format(port)) as ws:
"http://127.0.0.1:{}".format(port)
) as ws:
await ws.send_str("hello")
async for msg in ws:
assert msg.data == "hello"
Expand Down
Loading
Loading