Skip to content

StopWatch_test: consume CPU time instead of waiting wall time - #10276

Merged
timosachsenberg merged 1 commit into
developfrom
claude/awesome-dirac-o71cqc
Sep 26, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
claude/awesome-dirac-o71cqc

Conversation

@timosachsenberg

Copy link
Copy Markdown
Contributor

Description

StopWatch_test fails now and then in CI, most recently on the macOS job of #9966 (line 179; it passed on a re-run).

Cause. The stop() section busy-waits a fixed wall time (0.2 s, then 0.1 s) and then requires the process to have received at least half of it as CPU time, i.e. at least half a core. CI runs four tests in parallel (ctest jobs = 4 in the CI test presets), on the 3-core macOS runner among others, so the test sometimes gets less than that. The affected assertions are lines 144, 152 and 179; the tight wall-time upper bounds (< 0.3 s, < 3 × t_wait) carried the same risk.

Change (test only, StopWatch_test.cpp).

  • New helper consumeCPU() busy-waits until a StopWatch probe has seen the requested CPU time. The watches under test read the same process counter and were started before the probe, so the CPU-time lower bounds now hold however busy the machine is; only the wall time needed grows with the load.
    • Between two probes it spins 1 ms in user space, so the system time stays low.
    • A 30 s wall-time cap makes a broken CPU clock fail the test instead of hanging it.
  • Wall-time checks are now relative to the CPU time (a single thread needs at least as much wall time as CPU time), plus a coarse < 60 s bound that still catches unit errors.
  • Lower bounds use a 0.8 factor to allow for the coarse CPU clock ticks (10 ms on POSIX, ~15.6 ms on Windows).
  • The relative checks (a stopped watch does not advance, the watch that kept running is ahead, resume() accumulates both intervals) and the existing Windows workarounds are unchanged.
  • std::clock() was not used as an independent reference because on Windows it measures wall time, not CPU time.

Validation (Linux, 4 cores). Test and busy loops pinned to the same core with taskset -c 0:

Scenario Old test New test
no load, 50 runs – 50/50, 0.37 s per run
3 busy loops on the same core, 10 runs 0/10 (lines 144, 152, 179) 10/10, 1.4 s per run
7 busy loops on the same core, 10 runs 0/10 (lines 144, 152, 179) 10/10, 2.8 s per run

Under load the new test measured 0.18 s user and 0.03 s system time for the 0.2 s interval.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file (test-only change, no entry)
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes (StopWatch_test as above)
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

🤖 Generated with Claude Code

https://claude.ai/code/session_015br53P8rFQMnErUa4SiMSX


Generated by Claude Code

The stop() section busy-waited a fixed wall time (0.2 s, then 0.1 s) and
then required the process to have received at least half of it as CPU
time. CI runs four tests in parallel (ctest jobs = 4), on the 3-core
macOS runner among others, so the test sometimes got less than half a
core and failed in lines 144, 152 and 179 (seen on #9966).

consumeCPU() busy-waits until a StopWatch probe has seen the requested
CPU time, so the CPU time assertions hold however busy the machine is;
only the wall time needed grows with the load. Wall-time checks are now
relative to the CPU time plus a coarse upper bound, and lower bounds
allow for the coarse CPU clock ticks (10 ms on POSIX, ~15.6 ms on
Windows). A 30 s wall-time cap keeps a broken CPU clock from hanging the
test.

Pinned to one core together with 3 (7) busy loops, the old test failed
10/10 times; the new one passed 10/10 (1.4 s / 2.8 s per run). Unloaded
it passed 50/50 at 0.37 s per run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015br53P8rFQMnErUa4SiMSX
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: aed6ef0a-0666-44fc-88f7-382bb5a93bd5

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4ddbb and 55a9aac.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/StopWatch_test.cpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@timosachsenberg
timosachsenberg merged commit 497d715 into develop Sep 26, 2026
33 checks passed
@timosachsenberg
timosachsenberg deleted the claude/awesome-dirac-o71cqc branch September 26, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants