Skip to content

Commit 54a0c53

Browse files
refactor(profiling): move init_ddup to shared test_utils module
1 parent 7176023 commit 54a0c53

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

tests/profiling/collector/test_threading.py

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,6 @@
5656
]
5757

5858

59-
def _init_ddup(test_name: str) -> None:
60-
"""Initialize ddup for profiling tests.
61-
62-
Must be called before using any lock collectors.
63-
"""
64-
assert ddup.is_available, "ddup is not available"
65-
ddup.config(
66-
env="test",
67-
service=test_name,
68-
version="1.0",
69-
output_filename="/tmp/" + test_name,
70-
)
71-
ddup.start()
72-
73-
7459
# Module-level globals for testing global lock profiling
7560
_test_global_lock: LockTypeInst
7661

@@ -438,18 +423,10 @@ def test_assertion_error_raised_with_enable_asserts():
438423
import mock
439424
import pytest
440425

441-
from ddtrace.internal.datadog.profiling import ddup
442426
from ddtrace.profiling.collector.threading import ThreadingLockCollector
427+
from tests.profiling.collector.test_utils import init_ddup
443428

444-
# Initialize ddup (required before using collectors)
445-
assert ddup.is_available, "ddup is not available"
446-
ddup.config(
447-
env="test",
448-
service="test_asserts",
449-
version="1.0",
450-
output_filename="/tmp/test_asserts",
451-
)
452-
ddup.start()
429+
init_ddup("test_asserts")
453430

454431
with ThreadingLockCollector(capture_pct=100):
455432
lock = threading.Lock()
@@ -472,18 +449,10 @@ def test_all_exceptions_suppressed_by_default() -> None:
472449

473450
import mock
474451

475-
from ddtrace.internal.datadog.profiling import ddup
476452
from ddtrace.profiling.collector.threading import ThreadingLockCollector
453+
from tests.profiling.collector.test_utils import init_ddup
477454

478-
# Initialize ddup (required before using collectors)
479-
assert ddup.is_available, "ddup is not available"
480-
ddup.config(
481-
env="test",
482-
service="test_exceptions",
483-
version="1.0",
484-
output_filename="/tmp/test_exceptions",
485-
)
486-
ddup.start()
455+
init_ddup("test_exceptions")
487456

488457
with ThreadingLockCollector(capture_pct=100):
489458
lock = threading.Lock()
@@ -511,7 +480,9 @@ def test_semaphore_and_bounded_semaphore_collectors_coexist() -> None:
511480
e.g. when BoundedSemaphore's c-tor calls Semaphore c-tor.
512481
We expect that the call to Semaphore c-tor goes to the unpatched version, and NOT our patched version.
513482
"""
514-
_init_ddup("test_semaphore_and_bounded_semaphore_collectors_coexist")
483+
from tests.profiling.collector.test_utils import init_ddup
484+
485+
init_ddup("test_semaphore_and_bounded_semaphore_collectors_coexist")
515486

516487
# Both collectors active at the same time - this triggers the inheritance case
517488
with ThreadingSemaphoreCollector(capture_pct=100), ThreadingBoundedSemaphoreCollector(capture_pct=100):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Shared utilities for profiling collector tests."""
2+
3+
from ddtrace.internal.datadog.profiling import ddup
4+
5+
6+
def init_ddup(test_name: str) -> None:
7+
"""Initialize ddup for profiling tests.
8+
9+
Must be called before using any lock collectors.
10+
11+
Args:
12+
test_name: Name of the test, used for service name and output filename.
13+
"""
14+
assert ddup.is_available, "ddup is not available"
15+
ddup.config(
16+
env="test",
17+
service=test_name,
18+
version="1.0",
19+
output_filename="/tmp/" + test_name,
20+
)
21+
ddup.start()

0 commit comments

Comments
 (0)