Skip to content

compiletest: Fix deadline bugs in new executor #140031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged

Conversation

Zalathar
Copy link
Contributor

The experimental new executor for compiletest (#139660) was found to have two major bugs in deadline handling for detecting slow tests:

  • The comparison between now and test deadlines was reversed, causing no timeouts to ever be recognised.
  • After fixing that bug, it was found that the existing code would issue timeouts for any test that had started more than 60 seconds ago, even if the test had finished long before its deadline was reached.

This PR fixes those bugs.

(The new executor is not yet enabled by default, so this PR has no immediate effect on contributors.)


I noted in #139998 (comment) that I hoped to have some unit tests to accompany these fixes. Unfortunately that turned out to be infeasible, because DeadlineQueue is tightly coupled to concrete mpsc::Receiver APIs (in addition to Instant::now), and trying to mock all of those would make the code much more complicated.

I did, however, add a few assertions that would have caught the failure to remove tests from the queue after their deadline.

r? jieyouxu

@Zalathar Zalathar added the A-compiletest Area: The compiletest test runner label Apr 19, 2025
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@jieyouxu
Copy link
Member

I'll do some local testing of this on Monday (I'm out tmrw) unless someone beats me to it.

@Zalathar
Copy link
Contributor Author

For manual testing, I suggest changing the (hardcoded) timeout to 5 seconds, as there are several tests in the ui suite that will naturally take longer than that.

@Kobzol
Copy link
Contributor

Kobzol commented Apr 19, 2025

FWIW, you can test Instant::now() pretty easily even without dependency injection, by doing something like this:

#[cfg(test)]
fn now() -> Instant { return global or thread-local variable set in tests }

#[cfg(not(test))]
fn now() -> Instant {
    Instant::now()
}

@Zalathar
Copy link
Contributor Author

Some manual benchmark results from my machine after these changes:

$ x test ui -- --force-rerun
test result: ok. 18610 passed; 0 failed; 322 ignored; 0 measured; 0 filtered out; finished in 162.24s
test result: ok. 18610 passed; 0 failed; 322 ignored; 0 measured; 0 filtered out; finished in 163.28s
test result: ok. 18610 passed; 0 failed; 322 ignored; 0 measured; 0 filtered out; finished in 161.84s

$ x test ui -- --force-rerun -n
test result: ok. 18610 passed; 0 failed; 322 ignored; 0 measured; 0 filtered out; finished in 162.32s
test result: ok. 18610 passed; 0 failed; 322 ignored; 0 measured; 0 filtered out; finished in 163.64s
test result: ok. 18610 passed; 0 failed; 322 ignored; 0 measured; 0 filtered out; finished in 162.41s

(These are a bit quicker than my measurements in #139998, because I got rid of some background/indexing processes.)

@Zalathar
Copy link
Contributor Author

FWIW, you can test Instant::now() pretty easily even without dependency injection, by doing something like this:

Mocking Instant::now is not so bad, but after doing that I found that I still needed to find ways to mock things like mpsc::Receiver::recv_timeout and CollectedTest, which is harder. In my draft, it got to the point where DeadlineQueue contained more test scaffolding than code.

Maybe there's another design that makes testing easier, but I was reluctant to get too deep in the weeds of redesigning things to be fundamentally different from how libtest does it.

@jieyouxu
Copy link
Member

Haven't quite gotten to this PR today, I'll do the testing tmrw morning.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I exercised this locally on x86_64-unknown-linux-gnu and x86_64-pc-windows-msvc, and I am no longer observing the all-running-tests-produce-slow-warning behavior. Tested with a synthetic long-running foo.rs and changing deadline to 5s.

One style nit, but otherwise LGTM

@jieyouxu
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Zalathar
Copy link
Contributor Author

Rebased and added note to DeadlineQueue::now (diff).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 22, 2025
@jieyouxu
Copy link
Member

Thanks!
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 22, 2025

📌 Commit f7b1e03 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 22, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#139617 (Use posix_spawn on cygwin)
 - rust-lang#139921 (improve diagnostic for raw pointer field access with ->)
 - rust-lang#140031 (compiletest: Fix deadline bugs in new executor)
 - rust-lang#140072 (handle function alignment in miri)
 - rust-lang#140104 (Fix auto diff failing on inherent impl blocks)
 - rust-lang#140124 (Update books)
 - rust-lang#140144 (Handle another negated literal in `eat_token_lit`.)
 - rust-lang#140149 (test_nan: ensure the NAN contant is quiet)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 22, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#139617 (Use posix_spawn on cygwin)
 - rust-lang#139921 (improve diagnostic for raw pointer field access with ->)
 - rust-lang#140031 (compiletest: Fix deadline bugs in new executor)
 - rust-lang#140072 (handle function alignment in miri)
 - rust-lang#140104 (Fix auto diff failing on inherent impl blocks)
 - rust-lang#140124 (Update books)
 - rust-lang#140144 (Handle another negated literal in `eat_token_lit`.)
 - rust-lang#140149 (test_nan: ensure the NAN contant is quiet)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c046a43 into rust-lang:master Apr 23, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 23, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2025
Rollup merge of rust-lang#140031 - Zalathar:deadline, r=jieyouxu

compiletest: Fix deadline bugs in new executor

The experimental new executor for compiletest (rust-lang#139660) was found to have two major bugs in deadline handling for detecting slow tests:

- The comparison between `now` and test deadlines was reversed, causing no timeouts to ever be recognised.
- After fixing that bug, it was found that the existing code would issue timeouts for any test that had started more than 60 seconds ago, even if the test had finished long before its deadline was reached.

This PR fixes those bugs.

(The new executor is not yet enabled by default, so this PR has no immediate effect on contributors.)

---

I noted in rust-lang#139998 (comment) that I hoped to have some unit tests to accompany these fixes. Unfortunately that turned out to be infeasible, because `DeadlineQueue` is tightly coupled to concrete `mpsc::Receiver` APIs (in addition to `Instant::now`), and trying to mock all of those would make the code much more complicated.

I did, however, add a few assertions that would have caught the failure to remove tests from the queue after their deadline.

r? jieyouxu
@Zalathar Zalathar deleted the deadline branch April 23, 2025 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants