Skip to content

Commit c753095

Browse files
committed
update tests
1 parent 2af0c42 commit c753095

File tree

1 file changed

+22
-79
lines changed

1 file changed

+22
-79
lines changed

tests/profiling_v2/collector/test_stack.py

Lines changed: 22 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import uuid
88

99
import pytest
10-
from tests.profiling_v2.collector import test_collector
1110

1211
from ddtrace import ext
1312
from ddtrace.internal.datadog.profiling import ddup
1413
from ddtrace.profiling.collector import stack
1514
from tests.conftest import get_original_test_name
1615
from tests.profiling_v2.collector import pprof_utils
16+
from tests.profiling_v2.collector import test_collector
1717

1818

1919
# Python 3.11.9 is not compatible with gevent, https://github.com/gevent/gevent/issues/2040
@@ -25,6 +25,26 @@
2525
)
2626

2727

28+
def func1():
29+
return func2()
30+
31+
32+
def func2():
33+
return func3()
34+
35+
36+
def func3():
37+
return func4()
38+
39+
40+
def func4():
41+
return func5()
42+
43+
44+
def func5():
45+
return time.sleep(1)
46+
47+
2848
# Use subprocess as ddup config persists across tests.
2949
@pytest.mark.subprocess(
3050
env=dict(
@@ -35,10 +55,9 @@
3555
def test_collect_truncate():
3656
import os
3757

38-
from tests.profiling_v2.collector.test_stack import func1
39-
4058
from ddtrace.profiling import profiler
4159
from tests.profiling_v2.collector import pprof_utils
60+
from tests.profiling_v2.collector.test_stack import func1
4261

4362
pprof_prefix = os.environ["DD_PROFILING_OUTPUT_PPROF"]
4463
output_filename = pprof_prefix + "." + str(os.getpid())
@@ -830,79 +849,3 @@ def _trace():
830849

831850
for t in threads:
832851
t.join()
833-
834-
835-
@pytest.mark.skipif(not TESTING_GEVENT or sys.version_info < (3, 9), reason="Not testing gevent")
836-
@pytest.mark.subprocess(ddtrace_run=True)
837-
def test_collect_gevent_threads():
838-
import gevent.monkey
839-
840-
gevent.monkey.patch_all()
841-
842-
import os
843-
import threading
844-
import time
845-
846-
from ddtrace.internal.datadog.profiling import ddup
847-
from ddtrace.profiling.collector import stack
848-
from tests.profiling_v2.collector import pprof_utils
849-
850-
iteration = 100
851-
sleep_time = 0.01
852-
nb_threads = 15
853-
854-
# Start some greenthreads: they do nothing we just keep switching between them.
855-
def _nothing():
856-
for _ in range(iteration):
857-
# Do nothing and just switch to another greenlet
858-
time.sleep(sleep_time)
859-
860-
test_name = "test_collect_gevent_threads"
861-
pprof_prefix = "/tmp/" + test_name
862-
output_filename = pprof_prefix + "." + str(os.getpid())
863-
864-
assert ddup.is_available
865-
ddup.config(env="test", service="test_collect_gevent_threads", version="my_version", output_filename=pprof_prefix)
866-
ddup.start()
867-
868-
with stack.StackCollector():
869-
threads = []
870-
i_to_tid = {}
871-
for i in range(nb_threads):
872-
t = threading.Thread(target=_nothing, name="TestThread %d" % i)
873-
i_to_tid[i] = t.ident
874-
t.start()
875-
threads.append(t)
876-
for t in threads:
877-
t.join()
878-
879-
ddup.upload()
880-
881-
profile = pprof_utils.parse_newest_profile(output_filename)
882-
samples = pprof_utils.get_samples_with_label_key(profile, "task name")
883-
assert len(samples) > 0
884-
885-
for task_id in range(nb_threads):
886-
pprof_utils.assert_profile_has_sample(
887-
profile,
888-
samples,
889-
expected_sample=pprof_utils.StackEvent(
890-
task_name="TestThread %d" % task_id,
891-
task_id=i_to_tid[task_id],
892-
thread_id=i_to_tid[task_id],
893-
locations=[
894-
pprof_utils.StackLocation(
895-
filename="test_stack.py",
896-
function_name="_nothing",
897-
line_no=_nothing.__code__.co_firstlineno + 3,
898-
)
899-
],
900-
),
901-
)
902-
pprof_utils.assert_profile_has_sample(
903-
profile,
904-
samples,
905-
expected_sample=pprof_utils.StackEvent(
906-
task_name="MainThread",
907-
),
908-
)

0 commit comments

Comments
 (0)