nextest icon indicating copy to clipboard operation
nextest copied to clipboard

Manipulating the terminal causes tests to be stuck (linux)

Open sigmaSd opened this issue 1 year ago • 4 comments

code:

cargo add crossterm

#[test]
fn t() {
    // both of these freeze cargo next-test run
    // crossterm::terminal::enable_raw_mode().unwrap();
    // crossterm::cursor::position().unwrap();
}

sigmaSd avatar Aug 30 '23 11:08 sigmaSd

Thanks. This is a good flag -- what's happened is that this causes the child to raise a SIGTTOU signal on itself, and the default behavior of that signal is to put the process in a stopped state (similar to ctrl-Z). Nextest doesn't currently know how to deal with tests in this kind of stopped state.

  • At the very least, nextest definitely should ensure that if a test gets into a stopped state, termination via SIGINT/SIGTERM/timeouts continues to work.
  • I wish there were a way to change the signal handler for SIGTTOU/SIGTTIN to terminate the process, but I don't believe there is.
  • There was a suggestion at some point to use a pty for each test. We didn't do it for complexity reasons but maybe we should implement it as an option, and let tests opt into it. That would enable tests that do terminal manipulation to work.

sunshowers avatar Aug 30 '23 18:08 sunshowers

I wish there were a way to change the signal handler for SIGTTOU/SIGTTIN to terminate the process, but I don't believe there is.

Probably too intrusive for a test runner, to be honest. I think the out-of-process mechanics used by nextest (termination, timeouts) should generally be the extent of what we do.

The pty would definitely be interesting as well.

sunshowers avatar Aug 30 '23 19:08 sunshowers

Recently tried using the portable_pty crate (commit here) to test a TUI application; nextest seems to work with it.

ClementTsang avatar Jan 15 '24 06:01 ClementTsang

Yes, if we allow using a pty for each test, then I was eyeing the portable_pty crate to make that happen.

sunshowers avatar Jan 15 '24 19:01 sunshowers