Skip to content
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

Handing Ctrl+C in test harness #83326

Open
clarfonthey opened this issue Mar 20, 2021 · 2 comments
Open

Handing Ctrl+C in test harness #83326

clarfonthey opened this issue Mar 20, 2021 · 2 comments
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Mar 20, 2021

Right now, sending a Ctrl+C (SIGINT) as the test harness runs simply runs the default signal handler from the OS, which ends the process as soon as possible. It would be more ideal to handle this signal and end the harness more gracefully. Here's sort of what I have in mind:

  1. If the user presses Ctrl+C once, the harness will mark all tests that haven't started as ignored, wait for the currently running tests to finish, and then show the test results.
  2. If the user presses Ctrl+C twice, show results after the first thread finishes running a test, without waiting for all tests to finish. This could act as a safeguard in case one test is hanging. The remaining threads will terminate regardless after results are printed when the process exits.
  3. If the user presses Ctrl+C thrice, exit immediately.

Note that the second ctrl+C is only useful if more than one thread is running or if there are fewer hanging tests than running threads, but it seems reasonable to cover the case where one thread is hanging but the rest have finished.

Note that right now, this would require relying on an external crate like ctrlc since there's no built-in Rust way to do this, but I think that adding this option at least on platforms that support it would be extremely helpful.

@jonas-schievink jonas-schievink added A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Mar 20, 2021
@osa1
Copy link
Contributor

osa1 commented Mar 22, 2021

I proposed this on Zulip a while ago, though my design was simpler: just show the current stats (list failing tests) on C-c before exiting.

One blocker is the ctrlc crate does not build with 'rustc-dep-of-std' feature because it depends on 'extra_traits' feature of libc, which does not compile when combined with 'rustc-dep-of-std'. I have a WIP PR here to fix that: rust-lang/libc#2074

Once that's done we will be able to add ctrlc as a dependency to the test harness.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Mar 22, 2021

So that would basically fall under 3 of the implementation I gave. If you can reliably print stats before closing without blocking it's best to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
Status: No status
Development

No branches or pull requests

3 participants