Skip to content

Commit 6cd4b10

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 double the sampling run time. We could do 10x instead? And/or move the heuristic into test_support. Thoughts?
1 parent 237dca5 commit 6cd4b10

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 13 additions & 2 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
@@ -1904,7 +1907,10 @@ def test_sample_target_script(self):
19041907
script_file.flush()
19051908
self.addCleanup(close_and_unlink, script_file)
19061909

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

19091915
with (
19101916
mock.patch("sys.argv", test_args),
@@ -1936,7 +1942,12 @@ def test_sample_target_module(self):
19361942
with open(module_path, "w") as f:
19371943
f.write(self.test_script)
19381944

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

19411952
with (
19421953
mock.patch("sys.argv", test_args),

0 commit comments

Comments
 (0)