Skip to content

Commit

Permalink
split sync and async tests (fix review)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Sep 17, 2024
1 parent ebca082 commit 0e8f8d1
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import uuid
from typing import Any, List, Sequence, Tuple
from unittest import IsolatedAsyncioTestCase, mock
from unittest import IsolatedAsyncioTestCase, TestCase, mock

from aiokafka import (
AIOKafkaConsumer,
Expand All @@ -33,7 +33,28 @@
from opentelemetry.trace import SpanKind, format_trace_id, set_span_in_context


class TestAIOKafka(TestBase, IsolatedAsyncioTestCase):
class TestAIOKafkaInstrumentor(TestCase):
def test_instrument_api(self) -> None:
instrumentation = AIOKafkaInstrumentor()

instrumentation.instrument()
self.assertTrue(
isinstance(AIOKafkaProducer.send, BoundFunctionWrapper)
)
self.assertTrue(
isinstance(AIOKafkaConsumer.getone, BoundFunctionWrapper)
)

instrumentation.uninstrument()
self.assertFalse(
isinstance(AIOKafkaProducer.send, BoundFunctionWrapper)
)
self.assertFalse(
isinstance(AIOKafkaConsumer.getone, BoundFunctionWrapper)
)


class TestAIOKafkaInstrumentation(TestBase, IsolatedAsyncioTestCase):
@staticmethod
def consumer_record_factory(
number: int, headers: Tuple[Tuple[str, bytes], ...]
Expand Down Expand Up @@ -79,25 +100,6 @@ async def producer_factory() -> AIOKafkaProducer:

return producer

def test_instrument_api(self) -> None:
instrumentation = AIOKafkaInstrumentor()

instrumentation.instrument()
self.assertTrue(
isinstance(AIOKafkaProducer.send, BoundFunctionWrapper)
)
self.assertTrue(
isinstance(AIOKafkaConsumer.getone, BoundFunctionWrapper)
)

instrumentation.uninstrument()
self.assertFalse(
isinstance(AIOKafkaProducer.send, BoundFunctionWrapper)
)
self.assertFalse(
isinstance(AIOKafkaConsumer.getone, BoundFunctionWrapper)
)

async def test_getone(self) -> None:
AIOKafkaInstrumentor().uninstrument()
AIOKafkaInstrumentor().instrument(tracer_provider=self.tracer_provider)
Expand Down

0 comments on commit 0e8f8d1

Please sign in to comment.