Skip to content

Commit

Permalink
tests(aiohttp): adapt tests to OTel usage.
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
  • Loading branch information
pvital committed Sep 10, 2024
1 parent d93b8ec commit 820b226
Show file tree
Hide file tree
Showing 5 changed files with 644 additions and 606 deletions.
13 changes: 13 additions & 0 deletions tests/apps/aiohttp_app2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# (c) Copyright IBM Corp. 2024

import os
import sys
from tests.apps.aiohttp_app2.app import aiohttp_server as server
from tests.apps.utils import launch_background_thread

APP_THREAD = None

if not any((os.environ.get('GEVENT_STARLETTE_TEST'),
os.environ.get('CASSANDRA_TEST'),
sys.version_info < (3, 5, 3))):
APP_THREAD = launch_background_thread(server, "AIOHTTP")
40 changes: 40 additions & 0 deletions tests/apps/aiohttp_app2/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# (c) Copyright IBM Corp. 2024

import asyncio

from aiohttp import web

from tests.helpers import testenv

testenv["aiohttp_port"] = 10810
testenv["aiohttp_server"] = f"http://127.0.0.1:{testenv['aiohttp_port']}"


def say_hello(request):
return web.Response(text="Hello, world")


@web.middleware
async def middleware1(request, handler):
print("Middleware 1 called")
response = await handler(request)
print("Middleware 1 finished")
return response


def aiohttp_server():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

app = web.Application(middlewares=[middleware1])
app.add_routes([web.get("/", say_hello)])

runner = web.AppRunner(app)
loop.run_until_complete(runner.setup())
site = web.TCPSite(runner, "127.0.0.1", testenv["aiohttp_port"])

loop.run_until_complete(site.start())
loop.run_forever()
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
collect_ignore_glob.append("*clients/test_redis*")
collect_ignore_glob.append("*clients/test_sql*")

collect_ignore_glob.append("*frameworks/test_aiohttp*")
collect_ignore_glob.append("*frameworks/test_celery*")
collect_ignore_glob.append("*frameworks/test_gevent*")
collect_ignore_glob.append("*frameworks/test_grpcio*")
Expand Down
Loading

0 comments on commit 820b226

Please sign in to comment.