Use `cpu_perf_headroom()` for timing-test deadlines

`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
Gud Boi 2026-06-18 17:48:22 -04:00
parent 9c083c7cf8
commit 11d3c1ee58
2 changed files with 16 additions and 15 deletions

View File

@ -788,7 +788,7 @@ def test_cancel_via_SIGINT_other_task(
started from a seperate ``trio`` child task. started from a seperate ``trio`` child task.
''' '''
from .conftest import cpu_scaling_factor from .conftest import cpu_perf_headroom
pid: int = os.getpid() pid: int = os.getpid()
timeout: float = ( timeout: float = (
@ -798,8 +798,9 @@ def test_cancel_via_SIGINT_other_task(
if _friggin_windows: # smh if _friggin_windows: # smh
timeout += 1 timeout += 1
# add latency headroom for CPU freq scaling (auto-cpufreq et al.) # latency headroom for static cpu-freq scaling + sustained-load
headroom: float = cpu_scaling_factor() # throttle + CI (auto-cpufreq et al.); see `cpu_perf_headroom()`.
headroom: float = cpu_perf_headroom()
if headroom != 1.: if headroom != 1.:
timeout *= headroom timeout *= headroom
@ -995,11 +996,11 @@ def test_fast_graceful_cancel_when_spawn_task_in_soft_proc_wait_for_daemon(
if _friggin_windows: # smh if _friggin_windows: # smh
timeout += 1 timeout += 1
# CPU-scaling / CI latency headroom — macOS CI especially is # CPU-scaling / sustained-throttle / CI latency headroom — macOS
# slow for this graceful-vs-hard-reap timing race; see # CI especially is slow for this graceful-vs-hard-reap timing
# `cpu_scaling_factor()`. # race; see `cpu_perf_headroom()`.
from .conftest import cpu_scaling_factor from .conftest import cpu_perf_headroom
timeout *= cpu_scaling_factor() timeout *= cpu_perf_headroom()
async def main(): async def main():
start = time.time() start = time.time()

View File

@ -326,11 +326,11 @@ def time_quad_ex(
): ):
timeout += 1 timeout += 1
# inflate the cancel-deadline for CPU-freq scaling AND/OR CI # inflate the cancel-deadline for static cpu-freq scaling +
# latency (see `cpu_scaling_factor()`) so the example isn't # sustained-load throttle + CI latency (see `cpu_perf_headroom()`)
# cancelled mid-stream on a throttled/CI runner. # so the example isn't cancelled mid-stream on a throttled/CI box.
from .conftest import cpu_scaling_factor from .conftest import cpu_perf_headroom
timeout *= cpu_scaling_factor() timeout *= cpu_perf_headroom()
start: float = time.time() start: float = time.time()
results: list[int] = trio.run(partial( 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 # https://github.com/AdnanHodzic/auto-cpufreq?tab=readme-ov-file#example-config-file-contents
# #
# HENCE this below latency-headroom compensation logic.. # HENCE this below latency-headroom compensation logic..
from .conftest import cpu_scaling_factor from .conftest import cpu_perf_headroom
headroom: float = cpu_scaling_factor() headroom: float = cpu_perf_headroom()
if headroom != 1.: if headroom != 1.:
this_fast = this_fast_on_linux * headroom this_fast = this_fast_on_linux * headroom
test_log.warning( test_log.warning(