Skip to content

Commit

Permalink
Fix aiohttp Failures (#1123)
Browse files Browse the repository at this point in the history
* Update aiohttp in tests

* Remove unnecessary and buggy tests

* [Mega-Linter] Apply linters fixes

* Bump tests

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>
  • Loading branch information
TimPansino and TimPansino authored Apr 16, 2024
1 parent 240ea2e commit c55b4d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 66 deletions.
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

0 comments on commit c55b4d0

Please sign in to comment.