Skip to content

Commit ffacf28

Browse files
authored
Merge pull request #901 from jd/fix-opentracer-start-custom-time
[opentracer] Fix flaky test based on sleep
2 parents 17746c0 + 3c7ba44 commit ffacf28

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tests/opentracer/test_tracer.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ddtrace.propagation.http import HTTP_HEADER_TRACE_ID
1717
from ddtrace.settings import ConfigException
1818

19+
import mock
1920
import pytest
2021

2122

@@ -125,13 +126,14 @@ def test_start_span_references(self, ot_tracer, writer):
125126

126127
def test_start_span_custom_start_time(self, ot_tracer):
127128
"""Start a span with a custom start time."""
128-
t = time.time() + 0.002
129-
with ot_tracer.start_span('myop', start_time=t) as span:
130-
time.sleep(0.005)
129+
t = 100
130+
with mock.patch('time.time') as time:
131+
time.return_value = 102
132+
with ot_tracer.start_span('myop', start_time=t) as span:
133+
pass
131134

132-
# it should be certain that the span duration is strictly less than
133-
# the amount of time we sleep for
134-
assert span._dd_span.duration < 0.005
135+
assert span._dd_span.start == t
136+
assert span._dd_span.duration == 2
135137

136138
def test_start_span_with_spancontext(self, ot_tracer, writer):
137139
"""Start and finish a span using a span context as the child_of

0 commit comments

Comments
 (0)