Use `cpu_perf_headroom()` at remaining deadlines

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
Gud Boi 2026-06-29 17:54:46 -04:00
parent b6184ab74e
commit 2e605da264
4 changed files with 12 additions and 11 deletions

View File

@ -145,7 +145,7 @@ def test_example(
'This test does run just fine "in person" however..'
)
from .conftest import cpu_scaling_factor
from .conftest import cpu_perf_headroom
timeout: float = (
60
@ -153,8 +153,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

View File

@ -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'
)

View File

@ -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

View File

@ -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: