Skip to content

Signal handling and process management testing using rexpect - #11178

Closed
IanManske wants to merge 17 commits into
nushell:mainfrom
IanManske:rexpect
Closed

IanManske wants to merge 17 commits into
nushell:mainfrom
IanManske:rexpect

Conversation

@IanManske

Copy link
Copy Markdown
Member

Description

This PR adds testing for signal handling and process management using the rexpect crate and aims to resolve issue #6591. In the future, this can hopefully be used to test job handling as well.

@IanManske

IanManske commented Nov 28, 2023 •

Copy link
Copy Markdown
Member Author

This is very much still a WIP, but the PR should work as it currently is when combined with some changes to reedline: https://github.com/IanManske/reedline/tree/temp-cursor-fix
nushell/reedline#673
(This PR doesn't include these changes, so failing CI is expected.)

One minor issue is that reedline needs the cursor position to draw the prompt, but the terminal created by rexpect doesn't provide a position. I've made it so that a default position is provided, but this can only happen after the crossterm polling fails (hardcoded to 2 seconds). Since each send_nu_line triggers the cursor position query, then the tests can take unnecessarily long. Found a workaround.

@sholderbach

Copy link
Copy Markdown
Member

Love it that you tackle this hole in our testing!
I think massaging reedline so it can be tested with something like rexpect would be great for the lack of testing on reedline as well even if there are some limitations what can truly be tested more integration tests would be gretat.

@IanManske

Copy link
Copy Markdown
Member Author

Notes:

  • Needs to use bash instead of sh to test being put into the background. This unfortunately conflicts with Replace bash with POSIX sh in tests #11293.
  • Running the tests pollutes nu history. Is there way to disable history or change the history file?
  • Waiting on Respect termios ECHO flag reedline#673. Most tests happen to not need this PR, but future tests including the added par_each_ctrl_c test will need it (or some other workaround).

@IanManske
IanManske marked this pull request as ready for review December 19, 2023 16:32
sholderbach pushed a commit that referenced this pull request Dec 21, 2023
# Description
Simplifies `SIGQUIT` protection to a single `signal` ignore system call.

# User-Facing Changes
`SIGQUIT` is no longer blocked if nushell is in non-interactive mode
(signals should not be blocked in non-interactive mode).
Also a breaking API change for `nu_protocol`.

# Tests + Formatting
Should come after #11178 for testing.
}

#[test]
#[ignore] // currently fails, issue #7154

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be good to add the comment into the ignore message for our future selves (#[ignore = " ... "]).

fdncred pushed a commit that referenced this pull request Jan 15, 2024
# Description / User-Facing Changes
Signals are no longer blocked for child processes launched from both
interactive and non-interactive mode. The only exception is that
`SIGTSTP`, `SIGTTIN`, and `SIGTTOU` remain blocked for child processes
launched only from **interactive** mode. This is to help prevent nushell
from getting into an unrecoverable state, since we don't support
background jobs. Anyways, this fully fixes #9026.

# Other Notes
- Needs Rust version `>= 1.66` for a fix in
`std::process::Command::spawn`, but it looks our current Rust version is
way above this.
- Uses `sigaction` instead of `signal`, since the behavior of `signal`
can apparently differ across systems. Also, the `sigaction` man page
says:
> The sigaction() function supersedes the signal() function, and should
be used in preference.

Additionally, using both `sigaction` and `signal` is not recommended.
Since we were already using `sigaction` in some places (and possibly
some of our dependencies as well), this PR replaces all usages of
`signal`.

# Tests
Might want to wait for #11178 for testing.
@IanManske
IanManske marked this pull request as draft January 17, 2024 20:30
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Simplifies `SIGQUIT` protection to a single `signal` ignore system call.

# User-Facing Changes
`SIGQUIT` is no longer blocked if nushell is in non-interactive mode
(signals should not be blocked in non-interactive mode).
Also a breaking API change for `nu_protocol`.

# Tests + Formatting
Should come after nushell#11178 for testing.
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description / User-Facing Changes
Signals are no longer blocked for child processes launched from both
interactive and non-interactive mode. The only exception is that
`SIGTSTP`, `SIGTTIN`, and `SIGTTOU` remain blocked for child processes
launched only from **interactive** mode. This is to help prevent nushell
from getting into an unrecoverable state, since we don't support
background jobs. Anyways, this fully fixes nushell#9026.

# Other Notes
- Needs Rust version `>= 1.66` for a fix in
`std::process::Command::spawn`, but it looks our current Rust version is
way above this.
- Uses `sigaction` instead of `signal`, since the behavior of `signal`
can apparently differ across systems. Also, the `sigaction` man page
says:
> The sigaction() function supersedes the signal() function, and should
be used in preference.

Additionally, using both `sigaction` and `signal` is not recommended.
Since we were already using `sigaction` in some places (and possibly
some of our dependencies as well), this PR replaces all usages of
`signal`.

# Tests
Might want to wait for nushell#11178 for testing.
@WindSoilder

Copy link
Copy Markdown
Contributor

Thanks for proposing the PR. I think it's too old and still a draft PR. I'm going to close it. If you think the change is still necessary, feel free to resolve the conflict and open a new PR.

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.

4 participants