Skip to content

Commit

Permalink
test: added a unit test for set_attributes_from_context
Browse files Browse the repository at this point in the history
Signed-off-by: shivanshu <[email protected]>
  • Loading branch information
shivanshuraj1333 committed Dec 20, 2024
1 parent ef2ee8f commit ef93cb1
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,27 @@ def test_task_id_from_protocol_v2(self):

task_id = utils.retrieve_task_id_from_message(context)
self.assertEqual(task_id, "7e917b83-4018-431d-9832-73a28e1fb6c0")

def test_origin_and_hostname_attributes(self):
"""Test that 'origin' and 'hostname' are distinct attributes"""
# Create a mock span
span = mock.Mock()
span.is_recording.return_value = True

# Create a context with both 'origin' and 'hostname' keys
context = {
"origin": "gen8@b98c7aca4628",
"hostname": "celery@7c2c2cd6a5b5",
}

# Call the function
utils.set_attributes_from_context(span, context)

# Verify that both attributes were set with their original keys
span.set_attribute.assert_has_calls(
[
mock.call("celery.origin", "gen8@b98c7aca4628"),
mock.call("celery.hostname", "celery@7c2c2cd6a5b5"),
],
any_order=True,
)

0 comments on commit ef93cb1

Please sign in to comment.