Skip to content

Commit cc6bd3f

Browse files
committed
fix more testagent tests
1 parent ceb999d commit cc6bd3f

4 files changed

+29
-39
lines changed

tests/integration/test_integration_snapshots.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
from ddtrace import Tracer
99
from ddtrace import tracer
10-
from ddtrace.constants import AUTO_KEEP
11-
from ddtrace.constants import SAMPLING_PRIORITY_KEY
12-
from ddtrace.constants import USER_KEEP
1310
from tests.integration.utils import AGENT_VERSION
1411
from tests.integration.utils import mark_snapshot
1512
from tests.integration.utils import parametrize_with_all_encodings
@@ -21,7 +18,10 @@
2118

2219

2320
@snapshot(include_tracer=True)
21+
@pytest.mark.subprocess()
2422
def test_single_trace_single_span(tracer):
23+
from ddtrace import tracer
24+
2525
s = tracer.trace("operation", service="my-svc")
2626
s.set_tag("k", "v")
2727
# numeric tag
@@ -33,7 +33,10 @@ def test_single_trace_single_span(tracer):
3333

3434

3535
@snapshot(include_tracer=True)
36+
@pytest.mark.subprocess()
3637
def test_multiple_traces(tracer):
38+
from ddtrace import tracer
39+
3740
with tracer.trace("operation1", service="my-svc") as s:
3841
s.set_tag("k", "v")
3942
s.set_tag("num", 1234)
@@ -125,7 +128,6 @@ def test_tracer_trace_across_popen():
125128
the child span has does not have '_dd.p.dm' shows that sampling was run
126129
before fork automatically.
127130
"""
128-
tracer = Tracer()
129131

130132
def task(tracer):
131133
with tracer.trace("child"):
@@ -148,7 +150,6 @@ def test_tracer_trace_across_multiple_popens():
148150
the child span has does not have '_dd.p.dm' shows that sampling was run
149151
before fork automatically.
150152
"""
151-
tracer = Tracer()
152153

153154
def task(tracer):
154155
def task2(tracer):
@@ -170,9 +171,13 @@ def task2(tracer):
170171

171172

172173
@snapshot()
174+
@pytest.mark.subprocess()
173175
def test_wrong_span_name_type_not_sent():
174176
"""Span names should be a text type."""
175-
tracer = Tracer()
177+
import mock
178+
179+
from ddtrace import tracer
180+
176181
with mock.patch("ddtrace._trace.span.log") as log:
177182
with tracer.trace(123):
178183
pass
@@ -188,11 +193,9 @@ def test_wrong_span_name_type_not_sent():
188193
],
189194
)
190195
@pytest.mark.parametrize("encoding", ["v0.4", "v0.5"])
191-
@snapshot()
192196
def test_trace_with_wrong_meta_types_not_sent(encoding, meta, monkeypatch):
193197
"""Wrong meta types should raise TypeErrors during encoding and fail to send to the agent."""
194198
with override_global_config(dict(_trace_api=encoding)):
195-
tracer = Tracer()
196199
with mock.patch("ddtrace._trace.span.log") as log:
197200
with tracer.trace("root") as root:
198201
root._meta = meta
@@ -211,8 +214,6 @@ def test_trace_with_wrong_meta_types_not_sent(encoding, meta, monkeypatch):
211214
],
212215
)
213216
@pytest.mark.parametrize("encoding", ["v0.4", "v0.5"])
214-
@snapshot()
215-
@pytest.mark.xfail
216217
def test_trace_with_wrong_metrics_types_not_sent(encoding, metrics, monkeypatch):
217218
"""Wrong metric types should raise TypeErrors during encoding and fail to send to the agent."""
218219
with override_global_config(dict(_trace_api=encoding)):
@@ -226,9 +227,14 @@ def test_trace_with_wrong_metrics_types_not_sent(encoding, metrics, monkeypatch)
226227
log.exception.assert_called_once_with("error closing trace")
227228

228229

229-
@snapshot()
230+
@pytest.mark.subprocess()
231+
@pytest.mark.snapshot()
230232
def test_tracetagsprocessor_only_adds_new_tags():
231-
tracer = Tracer()
233+
from ddtrace import tracer
234+
from ddtrace.constants import AUTO_KEEP
235+
from ddtrace.constants import SAMPLING_PRIORITY_KEY
236+
from ddtrace.constants import USER_KEEP
237+
232238
with tracer.trace(name="web.request") as span:
233239
span.context.sampling_priority = AUTO_KEEP
234240
span.set_metric(SAMPLING_PRIORITY_KEY, USER_KEEP)

tests/integration/test_sampling.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import mock
21
import pytest
32

43
from ddtrace.constants import MANUAL_DROP_KEY
@@ -302,10 +301,14 @@ def test_extended_sampling_float_special_case_match_star(writer, tracer):
302301
span.set_tag("tag", 20.1)
303302

304303

304+
@pytest.mark.subprocess()
305305
def test_rate_limiter_on_spans(tracer):
306306
"""
307307
Ensure that the rate limiter is applied to spans
308308
"""
309+
from ddtrace import tracer
310+
from ddtrace.sampler import DatadogSampler
311+
309312
# Rate limit is only applied if a sample rate or trace sample rule is set
310313
tracer.configure(sampler=DatadogSampler(default_sample_rate=1, rate_limit=10))
311314
spans = []
@@ -329,10 +332,16 @@ def test_rate_limiter_on_spans(tracer):
329332
assert dropped_span.context.sampling_priority < 0
330333

331334

335+
@pytest.mark.subprocess()
332336
def test_rate_limiter_on_long_running_spans(tracer):
333337
"""
334338
Ensure that the rate limiter is applied on increasing time intervals
335339
"""
340+
import mock
341+
342+
from ddtrace import tracer
343+
from ddtrace.sampler import DatadogSampler
344+
336345
tracer.configure(sampler=DatadogSampler(rate_limit=5))
337346

338347
with mock.patch("ddtrace.internal.rate_limiter.time.monotonic_ns", return_value=1617333414):

tests/snapshots/tests.integration.test_integration_snapshots.test_trace_with_wrong_metrics_types_not_sent.json

-25
This file was deleted.

tests/snapshots/tests.integration.test_integration_snapshots.test_tracetagsprocessor_only_adds_new_tags.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[
22
{
33
"name": "web.request",
4-
"service": "tests.integration",
4+
"service": "ddtrace_subprocess_dir",
55
"resource": "web.request",
66
"trace_id": 0,
77
"span_id": 1,

0 commit comments

Comments
 (0)