Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aiohttp Failures #1123

Merged
merged 4 commits into from
Apr 16, 2024
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
67 changes: 3 additions & 64 deletions tests/framework_aiohttp/test_client_async_await.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import aiohttp
import pytest
from testing_support.fixtures import cat_enabled
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)
from yarl import URL

from newrelic.api.background_task import background_task
Expand Down Expand Up @@ -114,68 +116,6 @@ def task_test():
task_test()


@pytest.mark.parametrize("method,exc_expected", test_matrix)
def test_client_throw_async_await(event_loop, local_server_info, method, exc_expected):
class ThrowerException(ValueError):
pass

@background_task(name="test_client_throw_async_await")
async def self_driving_thrower():
async with aiohttp.ClientSession() as session:
coro = session._request(method.upper(), local_server_info.url)

# activate the coroutine
coro.send(None)

# inject error
coro.throw(ThrowerException())

@validate_transaction_metrics(
"test_client_throw_async_await",
background_task=True,
scoped_metrics=[
(local_server_info.base_metric + method.upper(), 1),
],
rollup_metrics=[
(local_server_info.base_metric + method.upper(), 1),
],
)
def task_test():
with pytest.raises(ThrowerException):
event_loop.run_until_complete(self_driving_thrower())

task_test()


@pytest.mark.parametrize("method,exc_expected", test_matrix)
def test_client_close_async_await(event_loop, local_server_info, method, exc_expected):
@background_task(name="test_client_close_async_await")
async def self_driving_closer():
async with aiohttp.ClientSession() as session:
coro = session._request(method.upper(), local_server_info.url)

# activate the coroutine
coro.send(None)

# force close
coro.close()

@validate_transaction_metrics(
"test_client_close_async_await",
background_task=True,
scoped_metrics=[
(local_server_info.base_metric + method.upper(), 1),
],
rollup_metrics=[
(local_server_info.base_metric + method.upper(), 1),
],
)
def task_test():
event_loop.run_until_complete(self_driving_closer())

task_test()


@pytest.mark.parametrize("method,exc_expected", test_matrix)
@cat_enabled
def test_await_request_async_await(event_loop, local_server_info, method, exc_expected):
Expand Down Expand Up @@ -240,7 +180,6 @@ def task_test():
@pytest.mark.parametrize("method,exc_expected", test_matrix)
@cat_enabled
def test_create_task_async_await(event_loop, local_server_info, method, exc_expected):

# `loop.create_task` returns a Task object which uses the coroutine's
# `send` method, not `__next__`

Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ envlist =
python-external_requests-{py27,py37,py38,py39,py310,py311,py312,pypy27,pypy310},
python-external_urllib3-{py27,py37,py38,py39,py310,py311,py312,pypy27,pypy310}-urllib3latest,
python-external_urllib3-{py27,py37,pypy27}-urllib3{0109},
python-framework_aiohttp-{py37,py38,py39,py310,py311,pypy310}-aiohttp03,
python-framework_aiohttp-py312-aiohttp030900rc0,
python-framework_aiohttp-{py37,py38,py39,py310,py311,py312,pypy310}-aiohttp03,
python-framework_ariadne-{py37,py38,py39,py310,py311,py312}-ariadnelatest,
python-framework_ariadne-py37-ariadne{0011,0012,0013},
python-framework_bottle-{py27,py37,py38,py39,py310,py311,py312,pypy27,pypy310}-bottle0012,
Expand Down
Loading