Skip to content

Commit 2f1f732

Browse files
committed
test(co): test for all snapshot IDs
We improve the testing by checking that all the snapshots referenced in span tags have been collected.
1 parent 39fef66 commit 2f1f732

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tests/debugging/origin/test_span.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from pathlib import Path
33
import typing as t
44

5-
import pytest
6-
75
import ddtrace
86
from ddtrace.debugging._origin.span import SpanCodeOriginProcessorEntry
97
from ddtrace.debugging._origin.span import SpanCodeOriginProcessorExit
@@ -47,6 +45,9 @@ def setUp(self):
4745
MockSpanCodeOriginProcessorEntry.enable()
4846
MockSpanCodeOriginProcessor.enable()
4947

48+
if (uploader := MockSpanCodeOriginProcessor.get_uploader()) is not None:
49+
uploader.flush()
50+
5051
def tearDown(self):
5152
ddtrace.tracer = self.backup_tracer
5253
super(SpanProbeTestCase, self).tearDown()
@@ -94,7 +95,6 @@ def entry_call():
9495
assert _exit.get_tag("_dd.code_origin.frames.0.file") == str(Path(__file__).resolve())
9596
assert _exit.get_tag("_dd.code_origin.frames.0.line") == str(self.test_span_origin.__code__.co_firstlineno)
9697

97-
@pytest.mark.skip(reason="Frequent unreliable failures")
9898
def test_span_origin_session(self):
9999
def entry_call():
100100
pass
@@ -111,7 +111,12 @@ def entry_call():
111111

112112
self.assert_span_count(3)
113113
entry, middle, _exit = self.get_spans()
114-
payloads = MockSpanCodeOriginProcessor.get_uploader().wait_for_payloads()
114+
115+
snapshot_ids_from_span_tags = {
116+
s.get_tag(f"_dd.code_origin.frames.{_}.snapshot_id") for s in (entry, middle, _exit) for _ in range(8)
117+
} - {None}
118+
119+
payloads = MockSpanCodeOriginProcessor.get_uploader().wait_for_payloads(len(snapshot_ids_from_span_tags))
115120
snapshot_ids = {p["debugger"]["snapshot"]["id"] for p in payloads}
116121

117122
assert len(payloads) == len(snapshot_ids)
@@ -125,9 +130,8 @@ def entry_call():
125130

126131
# Check that we have all the snapshots for the exit span
127132
assert _exit.get_tag("_dd.code_origin.type") == "exit"
128-
snapshot_ids_from_span_tags = {_exit.get_tag(f"_dd.code_origin.frames.{_}.snapshot_id") for _ in range(8)}
129-
snapshot_ids_from_span_tags.discard(None)
130-
assert snapshot_ids_from_span_tags < snapshot_ids
133+
134+
assert snapshot_ids_from_span_tags == snapshot_ids
131135

132136
# Check that we have complete data
133137
snapshot_ids_from_span_tags.add(entry_snapshot_id)

0 commit comments

Comments
 (0)