Skip to content

Commit 4f18889

Browse files
committed
pythongh-140381: Handle slower machines in test_profiling
While looking at python#140028 I found some test failures that are caused by new tests (from python#138122) running too slowly. This adds an arbitrary heuristic to 10x the sampling run time (to the default value of 10 seconds). Doubling the 1-second duration was sufficient for my HP PA tests, but Fedora reported one of the 2-second durations being too slow for a freethreaded build. This heuristic could move into test_support. Thoughts?
1 parent 237dca5 commit 4f18889

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import sys
1212
import tempfile
13+
import timeit
1314
import unittest
1415
from collections import namedtuple
1516
from unittest import mock
@@ -29,6 +30,8 @@
2930

3031
PROCESS_VM_READV_SUPPORTED = False
3132

33+
SLOW_MACHINE = timeit.timeit("2*2", number=10_000) > 0.0001
34+
3235
try:
3336
from _remote_debugging import PROCESS_VM_READV_SUPPORTED
3437
import _remote_debugging
@@ -1754,6 +1757,7 @@ def main_loop():
17541757
'''
17551758

17561759
def test_sampling_basic_functionality(self):
1760+
duration_sec = 10 if SLOW_MACHINE else 2
17571761
with (
17581762
test_subprocess(self.test_script) as subproc,
17591763
io.StringIO() as captured_output,
@@ -1762,7 +1766,7 @@ def test_sampling_basic_functionality(self):
17621766
try:
17631767
profiling.sampling.sample.sample(
17641768
subproc.process.pid,
1765-
duration_sec=2,
1769+
duration_sec=duration_sec,
17661770
sample_interval_usec=1000, # 1ms
17671771
show_summary=False,
17681772
)
@@ -1904,7 +1908,10 @@ def test_sample_target_script(self):
19041908
script_file.flush()
19051909
self.addCleanup(close_and_unlink, script_file)
19061910

1907-
test_args = ["profiling.sampling.sample", "-d", "1", script_file.name]
1911+
duration = 10 if SLOW_MACHINE else 1
1912+
test_args = [
1913+
"profiling.sampling.sample", "-d", str(duration), script_file.name
1914+
]
19081915

19091916
with (
19101917
mock.patch("sys.argv", test_args),
@@ -1936,7 +1943,12 @@ def test_sample_target_module(self):
19361943
with open(module_path, "w") as f:
19371944
f.write(self.test_script)
19381945

1939-
test_args = ["profiling.sampling.sample", "-d", "1", "-m", "test_module"]
1946+
duration = 10 if SLOW_MACHINE else 1
1947+
test_args = [
1948+
"profiling.sampling.sample",
1949+
"-d", str(duration),
1950+
"-m", "test_module"
1951+
]
19401952

19411953
with (
19421954
mock.patch("sys.argv", test_args),

0 commit comments

Comments
 (0)