Skip to content

Commit 892992e

Browse files
committed
tests(aiohttp): adapt tests to OTel usage.
Signed-off-by: Paulo Vital <[email protected]>
1 parent 62c1928 commit 892992e

File tree

5 files changed

+644
-606
lines changed

5 files changed

+644
-606
lines changed

tests/apps/aiohttp_app2/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# (c) Copyright IBM Corp. 2024
2+
3+
import os
4+
import sys
5+
from tests.apps.aiohttp_app2.app import aiohttp_server as server
6+
from tests.apps.utils import launch_background_thread
7+
8+
APP_THREAD = None
9+
10+
if not any((os.environ.get('GEVENT_STARLETTE_TEST'),
11+
os.environ.get('CASSANDRA_TEST'),
12+
sys.version_info < (3, 5, 3))):
13+
APP_THREAD = launch_background_thread(server, "AIOHTTP")

tests/apps/aiohttp_app2/app.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# (c) Copyright IBM Corp. 2024
5+
6+
import asyncio
7+
8+
from aiohttp import web
9+
10+
from tests.helpers import testenv
11+
12+
testenv["aiohttp_port"] = 10810
13+
testenv["aiohttp_server"] = f"http://127.0.0.1:{testenv['aiohttp_port']}"
14+
15+
16+
def say_hello(request):
17+
return web.Response(text="Hello, world")
18+
19+
20+
@web.middleware
21+
async def middleware1(request, handler):
22+
print("Middleware 1 called")
23+
response = await handler(request)
24+
print("Middleware 1 finished")
25+
return response
26+
27+
28+
def aiohttp_server():
29+
loop = asyncio.new_event_loop()
30+
asyncio.set_event_loop(loop)
31+
32+
app = web.Application(middlewares=[middleware1])
33+
app.add_routes([web.get("/", say_hello)])
34+
35+
runner = web.AppRunner(app)
36+
loop.run_until_complete(runner.setup())
37+
site = web.TCPSite(runner, "127.0.0.1", testenv["aiohttp_port"])
38+
39+
loop.run_until_complete(site.start())
40+
loop.run_forever()

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
collect_ignore_glob.append("*clients/test_redis*")
4545
collect_ignore_glob.append("*clients/test_sql*")
4646

47-
collect_ignore_glob.append("*frameworks/test_aiohttp*")
4847
collect_ignore_glob.append("*frameworks/test_celery*")
4948
collect_ignore_glob.append("*frameworks/test_gevent*")
5049
collect_ignore_glob.append("*frameworks/test_grpcio*")

0 commit comments

Comments
 (0)