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
12 changes: 7 additions & 5 deletions tests/datastore_asyncpg/test_multiple_dbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio

import asyncpg
import pytest
from testing_support.db_settings import postgresql_settings
from testing_support.fixtures import override_application_settings
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
from testing_support.util import instance_hostname
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

DB_MULTIPLE_SETTINGS = postgresql_settings()

ASYNCPG_VERSION = tuple(int(x) for x in getattr(asyncpg, "__version__", "0.0").split(".")[:2])
ASYNCPG_VERSION = get_package_version_tuple("asyncpg")

if ASYNCPG_VERSION < (0, 11):
CONNECT_METRICS = []
Expand Down Expand Up @@ -100,7 +101,6 @@


async def _exercise_db():

postgresql1 = DB_MULTIPLE_SETTINGS[0]
postgresql2 = DB_MULTIPLE_SETTINGS[1]

Expand Down Expand Up @@ -145,6 +145,7 @@ async def _exercise_db():
)
@background_task()
def test_multiple_databases_enable_instance(event_loop):
assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(_exercise_db())


Expand All @@ -161,4 +162,5 @@ def test_multiple_databases_enable_instance(event_loop):
)
@background_task()
def test_multiple_databases_disable_instance(event_loop):
assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(_exercise_db())
12 changes: 11 additions & 1 deletion tests/datastore_asyncpg/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

DB_SETTINGS = postgresql_settings()[0]


PG_PREFIX = "Datastore/operation/Postgres/"
ASYNCPG_VERSION = tuple(int(x) for x in getattr(asyncpg, "__version__", "0.0").split(".")[:2])
ASYNCPG_VERSION = get_package_version_tuple("asyncpg")

if ASYNCPG_VERSION < (0, 11):
CONNECT_METRICS = ()
Expand Down Expand Up @@ -65,6 +66,7 @@ def conn(event_loop):
@background_task(name="test_single")
@pytest.mark.parametrize("method", ("execute",))
def test_single(event_loop, method, conn):
assert ASYNCPG_VERSION is not None
_method = getattr(conn, method)
event_loop.run_until_complete(_method("""SELECT 0"""))

Expand All @@ -81,6 +83,7 @@ def test_single(event_loop, method, conn):
@background_task(name="test_prepared_single")
@pytest.mark.parametrize("method", ("fetch", "fetchrow", "fetchval"))
def test_prepared_single(event_loop, method, conn):
assert ASYNCPG_VERSION is not None
_method = getattr(conn, method)
event_loop.run_until_complete(_method("""SELECT 0"""))

Expand All @@ -93,6 +96,7 @@ def test_prepared_single(event_loop, method, conn):
)
@background_task(name="test_prepare")
def test_prepare(event_loop, conn):
assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(conn.prepare("""SELECT 0"""))


Expand Down Expand Up @@ -125,6 +129,7 @@ async def amain():
# 2 statements
await conn.copy_from_query("""SELECT 0""", output=BytesIO())

assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(amain())


Expand All @@ -139,6 +144,7 @@ async def amain():
)
@background_task(name="test_select_many")
def test_select_many(event_loop, conn):
assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(conn.executemany("""SELECT $1::int""", ((1,), (2,))))


Expand All @@ -158,6 +164,7 @@ async def amain():
async with conn.transaction():
await conn.execute("""SELECT 0""")

assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(amain())


Expand All @@ -181,6 +188,7 @@ async def amain():

await conn.cursor("SELECT 0")

assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(amain())


Expand All @@ -200,6 +208,7 @@ async def amain():
)
@background_task(name="test_unix_socket_connect")
def test_unix_socket_connect(event_loop):
assert ASYNCPG_VERSION is not None
with pytest.raises(OSError):
event_loop.run_until_complete(asyncpg.connect("postgres://?host=/.s.PGSQL.THIS_FILE_BETTER_NOT_EXIST"))

Expand Down Expand Up @@ -233,4 +242,5 @@ async def amain():
finally:
await pool.close()

assert ASYNCPG_VERSION is not None
event_loop.run_until_complete(amain())
Loading