Skip to content

Commit

Permalink
Rename helper function for consistency
Browse files Browse the repository at this point in the history
The same function exists in the aiopg tests under a different name.
  • Loading branch information
ffe4 committed Aug 21, 2020
1 parent 70b6962 commit 7f43a85
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
POSTGRES_USER = os.getenv("POSTGRESQL_HOST ", "testuser")


def _await(coro):
def async_call(coro):
loop = asyncio.get_event_loop()
return loop.run_until_complete(coro)

Expand All @@ -27,7 +27,7 @@ def setUpClass(cls):
cls._cursor = None
cls._tracer = cls.tracer_provider.get_tracer(__name__)
AsyncPGInstrumentor().instrument(tracer_provider=cls.tracer_provider)
cls._connection = _await(
cls._connection = async_call(
asyncpg.connect(
database=POSTGRES_DB_NAME,
user=POSTGRES_USER,
Expand All @@ -42,7 +42,7 @@ def tearDownClass(cls):
AsyncPGInstrumentor().uninstrument()

def test_instrumented_execute_method_without_arguments(self, *_, **__):
_await(self._connection.execute("SELECT 42;"))
async_call(self._connection.execute("SELECT 42;"))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand All @@ -59,7 +59,7 @@ def test_instrumented_execute_method_without_arguments(self, *_, **__):
)

def test_instrumented_fetch_method_without_arguments(self, *_, **__):
_await(self._connection.fetch("SELECT 42;"))
async_call(self._connection.fetch("SELECT 42;"))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand All @@ -77,7 +77,7 @@ async def _transaction_execute():
async with self._connection.transaction():
await self._connection.execute("SELECT 42;")

_await(_transaction_execute())
async_call(_transaction_execute())

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(3, len(spans))
Expand Down Expand Up @@ -124,7 +124,7 @@ async def _transaction_execute():
await self._connection.execute("SELECT 42::uuid;")

with self.assertRaises(asyncpg.CannotCoerceError):
_await(_transaction_execute())
async_call(_transaction_execute())

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(3, len(spans))
Expand Down Expand Up @@ -167,7 +167,7 @@ async def _transaction_execute():
)

def test_instrumented_method_doesnt_capture_parameters(self, *_, **__):
_await(self._connection.execute("SELECT $1;", "1"))
async_call(self._connection.execute("SELECT $1;", "1"))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand Down Expand Up @@ -198,7 +198,7 @@ def setUpClass(cls):
AsyncPGInstrumentor(capture_parameters=True).instrument(
tracer_provider=cls.tracer_provider
)
cls._connection = _await(
cls._connection = async_call(
asyncpg.connect(
database=POSTGRES_DB_NAME,
user=POSTGRES_USER,
Expand All @@ -213,7 +213,7 @@ def tearDownClass(cls):
AsyncPGInstrumentor().uninstrument()

def test_instrumented_execute_method_with_arguments(self, *_, **__):
_await(self._connection.execute("SELECT $1;", "1"))
async_call(self._connection.execute("SELECT $1;", "1"))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand All @@ -231,7 +231,7 @@ def test_instrumented_execute_method_with_arguments(self, *_, **__):
)

def test_instrumented_fetch_method_with_arguments(self, *_, **__):
_await(self._connection.fetch("SELECT $1;", "1"))
async_call(self._connection.fetch("SELECT $1;", "1"))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand All @@ -246,7 +246,7 @@ def test_instrumented_fetch_method_with_arguments(self, *_, **__):
)

def test_instrumented_executemany_method_with_arguments(self, *_, **__):
_await(self._connection.executemany("SELECT $1;", [["1"], ["2"]]))
async_call(self._connection.executemany("SELECT $1;", [["1"], ["2"]]))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand All @@ -262,7 +262,7 @@ def test_instrumented_executemany_method_with_arguments(self, *_, **__):

def test_instrumented_execute_interface_error_method(self, *_, **__):
with self.assertRaises(asyncpg.InterfaceError):
_await(self._connection.execute("SELECT 42;", 1, 2, 3))
async_call(self._connection.execute("SELECT 42;", 1, 2, 3))
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertEqual(
Expand Down

0 comments on commit 7f43a85

Please sign in to comment.