Fix asyncio related warnings in tests (#2335)

* aiopg: fix runtime warnings when running tests

Fixes:
RuntimeWarning: coroutine 'MockCursor.execute' was never awaited
    cursor.execute(query)

* aio-pika: no need to return an awaitable in mocked method

No need to return an awaitable since the mocked method awaits
itself.
Fixes:
    RuntimeWarning: coroutine 'sleep' was never awaited

---------

Co-authored-by: Leighton Chen <lechen@microsoft.com>
This commit is contained in:
Riccardo Magliocchetti
2024-03-14 20:27:18 +01:00
committed by GitHub
parent 9b3d0b485e
commit 3273d8c39f
2 changed files with 6 additions and 14 deletions

View File

@ -75,9 +75,7 @@ class TestInstrumentedExchangeAioRmq7(TestCase):
with mock.patch.object(
PublishDecorator, "_get_publish_span"
) as mock_get_publish_span:
with mock.patch.object(
Exchange, "publish", return_value=asyncio.sleep(0)
) as mock_publish:
with mock.patch.object(Exchange, "publish") as mock_publish:
decorated_publish = PublishDecorator(
self.tracer, exchange
).decorate(mock_publish)
@ -101,9 +99,7 @@ class TestInstrumentedExchangeAioRmq7(TestCase):
mocked_not_recording_span = MagicMock()
mocked_not_recording_span.is_recording.return_value = False
mock_get_publish_span.return_value = mocked_not_recording_span
with mock.patch.object(
Exchange, "publish", return_value=asyncio.sleep(0)
) as mock_publish:
with mock.patch.object(Exchange, "publish") as mock_publish:
with mock.patch(
"opentelemetry.instrumentation.aio_pika.publish_decorator.propagate.inject"
) as mock_inject:
@ -158,9 +154,7 @@ class TestInstrumentedExchangeAioRmq8(TestCase):
with mock.patch.object(
PublishDecorator, "_get_publish_span"
) as mock_get_publish_span:
with mock.patch.object(
Exchange, "publish", return_value=asyncio.sleep(0)
) as mock_publish:
with mock.patch.object(Exchange, "publish") as mock_publish:
decorated_publish = PublishDecorator(
self.tracer, exchange
).decorate(mock_publish)
@ -184,9 +178,7 @@ class TestInstrumentedExchangeAioRmq8(TestCase):
mocked_not_recording_span = MagicMock()
mocked_not_recording_span.is_recording.return_value = False
mock_get_publish_span.return_value = mocked_not_recording_span
with mock.patch.object(
Exchange, "publish", return_value=asyncio.sleep(0)
) as mock_publish:
with mock.patch.object(Exchange, "publish") as mock_publish:
with mock.patch(
"opentelemetry.instrumentation.aio_pika.publish_decorator.propagate.inject"
) as mock_inject:

View File

@ -76,7 +76,7 @@ class TestAiopgInstrumentor(TestBase):
cnx = async_call(aiopg.connect(database="test"))
cursor = async_call(cnx.cursor())
query = "SELECT * FROM test"
cursor.execute(query)
async_call(cursor.execute(query))
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
@ -127,7 +127,7 @@ class TestAiopgInstrumentor(TestBase):
cnx = async_call(pool.acquire())
cursor = async_call(cnx.cursor())
query = "SELECT * FROM test"
cursor.execute(query)
async_call(cursor.execute(query))
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)