Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shivanshu Raj Shrivastava <[email protected]>
  • Loading branch information
shivanshuraj1333 committed Feb 19, 2025
1 parent 1061a83 commit 19b9b9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def add(x, y):
_TASK_REVOKED_TERMINATED_SIGNAL_KEY = "celery.terminated.signal"
_TASK_NAME_KEY = "celery.task_name"

_QUEUE_NAME = "queue"
_QUEUE_NAME = "celery"


class CeleryGetter(Getter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ def test_task(self):
self.assertEqual(consumer.parent.span_id, producer.context.span_id)
self.assertEqual(consumer.context.trace_id, producer.context.trace_id)

def test_queue_name(self):
CeleryInstrumentor().instrument()

result = task_add.delay(1, 2)

timeout = time.time() + 60 * 1 # 1 minutes from now
while not result.ready():
if time.time() > timeout:
break
time.sleep(0.05)

spans = self.sorted_spans(self.memory_exporter.get_finished_spans())
self.assertEqual(len(spans), 2)

consumer, producer = spans

self.assertEqual(consumer.name, "run/tests.celery_test_tasks.task_add")
self.assertEqual(consumer.kind, SpanKind.CONSUMER)
self.assertSpanHasAttributes(
consumer,
{
"celery.action": "run",
"celery.state": "SUCCESS",
SpanAttributes.MESSAGING_DESTINATION: "celery",
SpanAttributes.MESSAGING_SYSTEM: "celery",
"celery.task_name": "tests.celery_test_tasks.task_add",
},
)

def test_task_raises(self):
CeleryInstrumentor().instrument()

Expand Down

0 comments on commit 19b9b9b

Please sign in to comment.