Skip to content

Commit 8e9cdd7

Browse files
committed
Add test case
1 parent c81a6f7 commit 8e9cdd7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Lib/test/test_profiling/test_sampling_profiler/test_integration.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,3 +953,42 @@ def test_all_stacks_share_same_base_frame(self):
953953
f"missing the entry point function 'run_forever'. This indicates "
954954
f"incomplete stacks are being returned, likely due to frame cache "
955955
f"storing partial stack traces.")
956+
957+
958+
@requires_remote_subprocess_debugging()
959+
class TestSampleProfilerUnwinderArgs(unittest.TestCase):
960+
961+
def test_only_active_thread_mapping_matches_all_threads(self):
962+
calls = []
963+
964+
def fake_remote_unwinder(pid, **kwargs):
965+
calls.append((pid, kwargs))
966+
return object()
967+
968+
with (
969+
mock.patch(
970+
"profiling.sampling.sample._remote_debugging.RemoteUnwinder",
971+
side_effect=fake_remote_unwinder,
972+
),
973+
# Force the non-free-threaded code path regardless of build flavor.
974+
mock.patch("profiling.sampling.sample._FREE_THREADED_BUILD", False),
975+
):
976+
SampleProfiler(pid=123, sample_interval_usec=1000, all_threads=False)
977+
SampleProfiler(pid=123, sample_interval_usec=1000, all_threads=True)
978+
979+
self.assertEqual(len(calls), 2)
980+
981+
_, kwargs0 = calls[0]
982+
_, kwargs1 = calls[1]
983+
984+
self.assertIn("only_active_thread", kwargs0)
985+
self.assertIn("only_active_thread", kwargs1)
986+
987+
self.assertTrue(
988+
kwargs0["only_active_thread"],
989+
"Expected only_active_thread=True when all_threads=False",
990+
)
991+
self.assertFalse(
992+
kwargs1["only_active_thread"],
993+
"Expected only_active_thread=False when all_threads=True",
994+
)

0 commit comments

Comments
 (0)