Skip to content

Commit

Permalink
Make span gc test clearer.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielshaar committed Sep 18, 2024
1 parent 50dc60d commit 4520ab8
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions tests/tracer/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2069,28 +2069,14 @@ def test_gc_not_used_on_root_spans():
with tracer.trace("test-event"):
pass

objects = gc.get_objects()
assert len(objects) == 2
# It probably doesn't make sense to check the exact nature of the objects, but importantly, everything should get
# cleaned up (the root span, trace, context, etc.). If this is not the case, you can uncomment the following code
# to inspect the objects that are not being cleaned up.
# There should be no more span objects lingering around.
assert not any(str(object).startswith("<Span") for object in gc.get_objects())

# To check the exact nature of the objects and their references, use the following:

# for i, obj in enumerate(objects):
# print("--------------------")
# print(f"object {i}:", obj)
# print("referrers:", [f"object {objects.index(r)}" for r in gc.get_referrers(obj)[:-2]])
# print("referents:", [f"object {objects.index(r)}" if r in objects else r for r in gc.get_referents(obj)])
# print("--------------------")

# Expected output:
# --------------------
# object 0: <hamt_bitmap_node object at 0x7fa749e1db70>
# referrers: ['object 1']
# referents: [<sentry_sdk.hub.Hub object at 0x7fa745211450>, <ContextVar name='sentry_current_hub' at
# 0x7fa74516e660>, None, <ContextVar name='datadog_contextvar' default=None at 0x7fa7490064d0>]
# --------------------
# --------------------
# object 1: <hamt object at 0x7fa745239000>
# referrers: []
# referents: ['object 0']
# --------------------

0 comments on commit 4520ab8

Please sign in to comment.