test: measure rpcwaittimeout floor with monotonic time #36529

Manually merged
nervana21 merged 1 commit from test-rpcwaittimeout-slack into master 2026-10-27 18:41:08 +00:00 AGit
nervana21 commented 2026-10-14 20:43:59 +00:00 (Migrated from github.com)

Previously, interface_bitcoin_cli.py measured the -rpcwaittimeout wait floor with time.time(). bitcoin-cli arms that deadline with std::chrono::steady_clock, so a CI wall-clock step backward can make the elapsed time look short and cause the assert to fail.

Fix this by using time.monotonic() instead and using -rpcwaittimeout=1. The log line also now says "at least" so it matches the floor assert.

h/t ViniciusCestarii for suggesting time.monotonic() here.

Previously, `interface_bitcoin_cli.py` measured the `-rpcwaittimeout` wait floor with `time.time()`. `bitcoin-cli` arms that deadline with `std::chrono::steady_clock`, so a CI wall-clock step backward can make the elapsed time look short and cause the assert to fail. Fix this by using `time.monotonic()` instead and using `-rpcwaittimeout=1`. The log line also now says "at least" so it matches the floor assert. h/t ViniciusCestarii for suggesting `time.monotonic()` here.
DrahtBot commented 2026-10-14 20:44:10 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK maflcko, ViniciusCestarii

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36529 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36529.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36529#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/36529#issuecomment-6449227250), [ViniciusCestarii](https://github.com/bitcoin/bitcoin/pull/36529#pullrequestreview-5671883735) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Base: 23288073d4e7723bf7559a904bbf322a52d8af55
Head: dc27539d42bbfc04705d9ae1ea00cf70b046d8fa

Previous findings and author responses

Measure the timeout floor with a monotonic clock (test/functional/interface_bitcoin_cli.py:482, head)

This floor check uses time.time(), but bitcoin-cli computes and checks its timeout deadline with steady_clock. A wall-clock adjustment during the invocation can still skew the measured interval despite the 0.1-second slack. Use time.monotonic() for both samples, retaining any needed tolerance, and describe the timeout as elapsed/steady time rather than wall clock.

Previously reported. Status: fixed. Author position: rejected. Originally reported at 7445428eb851ab5314dab2cbe2dbe34fdd58200f. The earlier finding said the floor check used time.time() while bitcoin-cli enforces its deadline with steady_clock. At the current head both samples use time.monotonic(), and the assert checks the elapsed duration directly. The old 0.1s slack and its 'best effort wall clock' comment are gone. bitcoin-cli still sets and checks the deadline with steady_clock, so the test and CLI now use the same kind of clock. Keeping no slack is correct here because the start sample comes before the subprocess launches. Author reply 2026-10-27T17:04:58Z

Review tier: routine

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:50cda8eefddce112380bd344c1de4cacefba399bf37e0a9110a274ce289ea946:62e796dbd0f2259afd1838e4a53871f0138826c649eeb98ae74f1729f55b9d49 --> Base: `23288073d4e7723bf7559a904bbf322a52d8af55` Head: `dc27539d42bbfc04705d9ae1ea00cf70b046d8fa` <!-- ralph-case:d71af12edce113c91d42c2d1e9532c3e673b17429cffbe407c7e4af41b61938e --> ##### Previous findings and author responses **Measure the timeout floor with a monotonic clock** (test/functional/interface_bitcoin_cli.py:482, head) This floor check uses time.time(), but bitcoin-cli computes and checks its timeout deadline with steady_clock. A wall-clock adjustment during the invocation can still skew the measured interval despite the 0.1-second slack. Use time.monotonic() for both samples, retaining any needed tolerance, and describe the timeout as elapsed/steady time rather than wall clock. Previously reported. Status: fixed. Author position: rejected. Originally reported at `7445428eb851ab5314dab2cbe2dbe34fdd58200f`. The earlier finding said the floor check used `time.time()` while bitcoin-cli enforces its deadline with `steady_clock`. At the current head both samples use `time.monotonic()`, and the assert checks the elapsed duration directly. The old 0.1s slack and its 'best effort wall clock' comment are gone. bitcoin-cli still sets and checks the deadline with `steady_clock`, so the test and CLI now use the same kind of clock. Keeping no slack is correct here because the start sample comes before the subprocess launches. [Author reply](https://github.com/bitcoin/bitcoin/pull/36529#issuecomment-6448321761) 2026-10-27T17:04:58Z Review tier: routine [Full review report](<https://review.fish.foo/traces/36529-dc27539d42bbfc04705d9ae1ea00cf70b046d8fa-1508-10.html>)
maflcko (Migrated from github.com) reviewed 2026-10-23 09:01:56 +00:00
maflcko (Migrated from github.com) commented 2026-10-23 09:01:56 +00:00

seems fine, but the 5 can probably be reduced to 1, to speed up the test

seems fine, but the 5 can probably be reduced to `1`, to speed up the test
nervana21 commented 2026-10-25 16:13:09 +00:00 (Migrated from github.com)

Updates:

_**Updates**_: * Addressed @maflcko's [feedback](https://github.com/bitcoin/bitcoin/pull/36529#discussion_r4357865290)
maflcko commented 2026-10-26 17:00:00 +00:00 (Migrated from github.com)

lgtm ACK 7445428eb8

<!--meta-tag:bot-skip-->
lgtm ACK 7445428eb851ab5314dab2cbe2dbe34fdd58200f ``` <!--meta-tag:bot-skip-->
fanquake commented 2026-10-26 17:04:11 +00:00 (Migrated from github.com)

cc @ViniciusCestarii

cc @ViniciusCestarii
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-26 18:10:37 +00:00
ViniciusCestarii (Migrated from github.com) left a comment

start_time is taken before spawning bitcoin-cli and bitcoin-cli uses monotonic time, so the flake can only come from wall clock adjustment. Wouldn't replacing time.time() with time.monotonic() fix this without the slack?

`start_time` is taken before spawning bitcoin-cli and bitcoin-cli uses monotonic time, so the flake can only come from wall clock adjustment. Wouldn't replacing `time.time()` with `time.monotonic()` fix this without the slack?
maflcko commented 2026-10-27 06:28:30 +00:00 (Migrated from github.com)

Good catch, not sure how I missed this. I presume I was confused by the LHS and RHS both doing addition. Maybe it would be clearer to understand and to read the assertion error message, when the LHS was monotonic()-start_time, so that only the duration is printed. Steps to reproduce:

faketime --exclude-monotonic -f "+0 x0.5" ./bld-cmake/test/functional/interface_bitcoin_cli.py 
Good catch, not sure how I missed this. I presume I was confused by the LHS and RHS both doing addition. Maybe it would be clearer to understand and to read the assertion error message, when the LHS was `monotonic()-start_time`, so that only the duration is printed. Steps to reproduce: ``` faketime --exclude-monotonic -f "+0 x0.5" ./bld-cmake/test/functional/interface_bitcoin_cli.py ```
nervana21 commented 2026-10-27 17:04:58 +00:00 (Migrated from github.com)

Updates:

  • Addressed @ViniciusCestarii's feedback (use time.monotonic())

  • Addressed @maflcko's feedback (assert elapsed duration on the LHS)

_**Updates**:_ * Addressed @ViniciusCestarii's feedback (use `time.monotonic()`) * Addressed @maflcko's feedback (assert elapsed duration on the LHS)
maflcko commented 2026-10-27 17:40:19 +00:00 (Migrated from github.com)

lgtm ACK dc27539d42

lgtm ACK dc27539d42bbfc04705d9ae1ea00cf70b046d8fa
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-27 17:53:06 +00:00
ViniciusCestarii (Migrated from github.com) left a comment
ACK dc27539d42bbfc04705d9ae1ea00cf70b046d8fa
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36529
No description provided.