From 707caf63d17b2d12d1a5cf81bdc18277403c7fd6 Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 18 Jun 2026 17:48:22 -0400 Subject: [PATCH] Use `cpu_perf_headroom()` for timing-test deadlines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `cpu_perf_headroom()` is a strict SUPERSET of `cpu_scaling_factor()` — it folds in static cpu-freq scaling + the slow-CI bump AND the sustained-load power-cap throttle probe. Point the timing-deadline call sites at it so they're robust to sustained throttling too (the gremlin behind mass `trio` deadline-miss flakes), - `test_legacy_one_way_streaming`: `time_quad_ex` cancel-deadline + `test_a_quadruple_example`'s `this_fast` smoke bound. - `test_cancellation`: `test_cancel_via_SIGINT_other_task` + `test_fast_graceful_cancel_*` deadlines. `cpu_perf_headroom >= cpu_scaling_factor` always, so never less headroom (CI stays green); `cpu_scaling_factor()` remains the internal static component. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tests/test_cancellation.py | 17 +++++++++-------- tests/test_legacy_one_way_streaming.py | 14 +++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py index c7d67f65..bff4c0c2 100644 --- a/tests/test_cancellation.py +++ b/tests/test_cancellation.py @@ -788,7 +788,7 @@ def test_cancel_via_SIGINT_other_task( started from a seperate ``trio`` child task. ''' - from .conftest import cpu_scaling_factor + from .conftest import cpu_perf_headroom pid: int = os.getpid() timeout: float = ( @@ -798,8 +798,9 @@ def test_cancel_via_SIGINT_other_task( if _friggin_windows: # smh timeout += 1 - # add latency headroom for CPU freq scaling (auto-cpufreq et al.) - headroom: float = cpu_scaling_factor() + # latency headroom for static cpu-freq scaling + sustained-load + # throttle + CI (auto-cpufreq et al.); see `cpu_perf_headroom()`. + headroom: float = cpu_perf_headroom() if headroom != 1.: timeout *= headroom @@ -1002,11 +1003,11 @@ def test_fast_graceful_cancel_when_spawn_task_in_soft_proc_wait_for_daemon( if _friggin_windows: # smh timeout += 1 - # CPU-scaling / CI latency headroom — macOS CI especially is - # slow for this graceful-vs-hard-reap timing race; see - # `cpu_scaling_factor()`. - from .conftest import cpu_scaling_factor - timeout *= cpu_scaling_factor() + # CPU-scaling / sustained-throttle / CI latency headroom — macOS + # CI especially is slow for this graceful-vs-hard-reap timing + # race; see `cpu_perf_headroom()`. + from .conftest import cpu_perf_headroom + timeout *= cpu_perf_headroom() async def main(): start = time.time() diff --git a/tests/test_legacy_one_way_streaming.py b/tests/test_legacy_one_way_streaming.py index 648ba1b8..ade76763 100644 --- a/tests/test_legacy_one_way_streaming.py +++ b/tests/test_legacy_one_way_streaming.py @@ -326,11 +326,11 @@ def time_quad_ex( ): timeout += 1 - # inflate the cancel-deadline for CPU-freq scaling AND/OR CI - # latency (see `cpu_scaling_factor()`) so the example isn't - # cancelled mid-stream on a throttled/CI runner. - from .conftest import cpu_scaling_factor - timeout *= cpu_scaling_factor() + # inflate the cancel-deadline for static cpu-freq scaling + + # sustained-load throttle + CI latency (see `cpu_perf_headroom()`) + # so the example isn't cancelled mid-stream on a throttled/CI box. + from .conftest import cpu_perf_headroom + timeout *= cpu_perf_headroom() start: float = time.time() results: list[int] = trio.run(partial( @@ -379,8 +379,8 @@ def test_a_quadruple_example( # https://github.com/AdnanHodzic/auto-cpufreq?tab=readme-ov-file#example-config-file-contents # # HENCE this below latency-headroom compensation logic.. - from .conftest import cpu_scaling_factor - headroom: float = cpu_scaling_factor() + from .conftest import cpu_perf_headroom + headroom: float = cpu_perf_headroom() if headroom != 1.: this_fast = this_fast_on_linux * headroom test_log.warning(