From 63498a80c23f6120f3540f913eb12cbeacbff3b4 Mon Sep 17 00:00:00 2001 From: goodboy Date: Mon, 29 Jun 2026 17:54:46 -0400 Subject: [PATCH] Use `cpu_perf_headroom()` at remaining deadlines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Finish TODO #2 from PR #468: the last raw `cpu_scaling_factor()` call-sites still used the static-only check (blind to the sustained-load power-cap). Point them at the `cpu_perf_headroom()` SUPERSET — it calls `cpu_scaling_factor()` internally + the session-cached throttle probe, so it's always >= the old factor (never LESS headroom, so CI stays green). Migrated, - `test_spawning`: the `fail_after(1 * ...)` smoke deadline (#465-added). - `test_inter_peer_cancellation`: `this_fast` budget. - `test_docs_examples`: example-run `timeout`. - `test_resource_cache`: fan-out `timeout`. `test_cancellation` already used `cpu_perf_headroom()`; only its explanatory comments still name the static helper. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tests/test_docs_examples.py | 7 ++++--- tests/test_inter_peer_cancellation.py | 6 +++--- tests/test_resource_cache.py | 4 ++-- tests/test_spawning.py | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/test_docs_examples.py b/tests/test_docs_examples.py index 4f791727..cce85292 100644 --- a/tests/test_docs_examples.py +++ b/tests/test_docs_examples.py @@ -160,7 +160,7 @@ def test_example( 'root-causing. Passes on Linux.' ) - from .conftest import cpu_scaling_factor + from .conftest import cpu_perf_headroom timeout: float = ( 60 @@ -168,8 +168,9 @@ def test_example( else 16 ) - # add latency headroom for CPU freq scaling (auto-cpufreq et al.) - headroom: float = cpu_scaling_factor() + # add latency headroom for CPU freq scaling/throttle + # (auto-cpufreq et al.) + headroom: float = cpu_perf_headroom() if headroom != 1.: timeout *= headroom diff --git a/tests/test_inter_peer_cancellation.py b/tests/test_inter_peer_cancellation.py index 6bf74880..e0bf5dab 100644 --- a/tests/test_inter_peer_cancellation.py +++ b/tests/test_inter_peer_cancellation.py @@ -24,7 +24,7 @@ from tractor._testing import ( expect_ctxc, ) -from .conftest import cpu_scaling_factor +from .conftest import cpu_perf_headroom pytestmark = [ pytest.mark.skipon_spawn_backend( @@ -1280,12 +1280,12 @@ def test_peer_spawns_and_cancels_service_subactor( async def _main(): - headroom: float = cpu_scaling_factor() + headroom: float = cpu_perf_headroom() this_fast_on_linux: float = 3 this_fast = this_fast_on_linux * headroom if headroom != 1.: test_log.warning( - f'Adding latency headroom on linux bc CPU scaling,\n' + f'Adding latency headroom on linux bc CPU perf scaling/throttle,\n' f'headroom: {headroom}\n' f'this_fast_on_linux: {this_fast_on_linux} -> {this_fast}\n' ) diff --git a/tests/test_resource_cache.py b/tests/test_resource_cache.py index 4902fb7a..049c0a6b 100644 --- a/tests/test_resource_cache.py +++ b/tests/test_resource_cache.py @@ -213,12 +213,12 @@ def test_open_local_sub_to_stream( N local tasks using `trionics.maybe_open_context()`. ''' - from .conftest import cpu_scaling_factor + from .conftest import cpu_perf_headroom timeout: float = ( 4 if not platform.system() == "Windows" else 10 - ) * cpu_scaling_factor() + ) * cpu_perf_headroom() if debug_mode: timeout = 999 diff --git a/tests/test_spawning.py b/tests/test_spawning.py index b6128b96..6237282e 100644 --- a/tests/test_spawning.py +++ b/tests/test_spawning.py @@ -153,9 +153,9 @@ async def test_most_beautiful_word( # actor spawn + IPC round-trip is comfortably sub-second on a # warm box, but slow/noisy CI runners (esp. macOS) blow a flat # 1s deadline. Scale for CI/CPU-throttle headroom — `== 1s` - # locally where `cpu_scaling_factor()` is `1.0`. - from .conftest import cpu_scaling_factor - with trio.fail_after(1 * cpu_scaling_factor()): + # locally where `cpu_perf_headroom()` is `1.0`. + from .conftest import cpu_perf_headroom + with trio.fail_after(1 * cpu_perf_headroom()): async with tractor.open_nursery( debug_mode=debug_mode, ) as an: