-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
CTRL+C does not immediately stop running tests #3569
Comments
Start a new pull request in StackBlitz Codeflow. |
I think this is an intended change, you need to press |
@nstepien does this happen only on Stackblitz or also on your local machine? I can reproduce this on Stackblitz but it works fine on my local machine, MacOS. |
For this specific example, pressing CTRL+C locally works fine. But in our project, trying to terminate vitest doesn't not immediately stop the tests no matter how many times I press CTRL+C. What's the reasoning for gracefully stopping tests? |
It should exit on the second SIGINT, so this is a bug. When implementing this feature I used multiple third party projects as reference for manual testing and they all worked fine. Without being able to reproduce this issue it's hard to identify the root cause. Could you test if your local project exits properly with
In #3373 it was requested that we print the test summary instead of exiting the process immediately. If we don't intercept the SIGINT, the Node process will exit immediately. |
Please try this open-source repo of ours: https://github.com/adazzle/react-data-grid
It does terminate immediately yes, though it doesn't print the test summary.
That makes sense to me. 👍 |
I've been trying to reproduce the issue for a while now but everything seems to work fine. I've tried cancelling the tests in different phases to see if some other test is causing this but cancelling with CTRL+C works all the times. Screen.Recording.2023-06-14.at.15.08.47.mov |
@nstepien could you try other terminals as well? I guess in the video above you are using Powershell? Please test what happens with CMD and Git Bash. |
@AriPerkkio I've now tried with both CMD and Git Bash, and the same thing happened, no difference in behavior with Powershell. I've also tried Windows Terminal instead of the terminal in VSCode, no luck there either. |
Great, thanks for testing. I'm running out of ideas. I don't have access to Windows machine at the moment so it's hard to debug this. But I guess this is indeed a Windows related issue. |
I don't think Windows supports |
I still wonder why changes of #3407 broke Windows though. I'm looking into setting virtual environment on my machine to be able to reproduce this. |
Because |
Then it should work as before and exit the process. Now it seems to cause some kind of blocking. @nstepien could you again do some testing and verify whether |
@sheremet-va import process from 'process';
process.once('SIGINT', () => {
console.log('Received SIGINT');
});
setTimeout(() => {
process.exit(0);
}, 100000); This will terminate the process on the second CTRL+C. @AriPerkkio My previous attempts were with |
Even on Windows 11 I'm unable to reproduce this issue. Below I'm pressing CTRL+C multiple times and the tests are skipped. windows-ctrl-c.mov |
@AriPerkkio Could you try with |
Still unable to reproduce. That |
That's fine, but not the issue at hand. |
It should, and that is happening on other platforms than Windows. That's why this is a bug. However I'm unable to reproduce this at all. For example running these two tests can be cancelled when first one is running. We can cancel test run without having to wait 4-5s. This is exactly what is being discussed here, right? test("this test takes 5000ms", async () => {
await sleep(5000);
});
test("this test takes 4000ms", async () => {
await sleep(4000);
}); # 1. Start tests
$ time pnpm test tests/slow.test.ts
RUN v0.32.2 /x/y/vitest-example-project
...
# 2. Wait 1-2s and press CTRL+C twice
❯ tests/slow.test.ts (2)
⠴ this test takes 5000ms
· this test takes 4000ms
ELIFECYCLE Test failed. See above for more details.
real 0m1.200s
user 0m0.649s
sys 0m0.087s
# 3. Process was terminated. We did not have to wait 4-5s.
$ |
I'm now able to reproduce this using the minimal example from above. This is clearly a Windows bug as on macOs the test case exits on second Screen.Recording.2023-06-19.at.20.24.42.mov |
Yep! |
I've been debugging this for a while and I think the root cause is identified now. In #3407 I assumed that Testing following script gives different SIGINT handling depending on OS and package manager: // index.mjs
setInterval(() => process.stdout.write("."), 500);
process.on("SIGINT", () => console.log("SIGINT received"));
// Helper to force exit after 10 seconds just to that we don't get stuck forever
setTimeout(() => {
console.log("Forcing timeout exit");
process.exit(0);
}, 10_000); {
"scripts": {
"start": "node index.mjs"
}
} Running the script above and hitting
So I guess we should not count on catching SIGINT at all. Maybe we should instead capture keys with |
Describe the bug
CTRL+C does not immediately stop Vitest when tests are slow or stuck.
I've seen Vitest being impossible to terminate when tests are stuck because of an issue with fake timers for example, I had to completely close the terminal.
When test are just particularly slow it's frustrating that Vitest doesn't immediately stops when pressing CTRL+C.
I think this affects
bail: 1
too, not 100% sure.Jest does not have this issue.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-c5wvvm?file=test%2Fsuite1.test.ts,test%2Fslow.test.ts,test%2Fsuite2.test.ts,vite.config.ts,test%2Fsuite0.test.ts&initialPath=__vitest__/
npm run test:run slow
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: