Giter Site home page Giter Site logo

Comments (5)

sunshowers avatar sunshowers commented on June 12, 2024

Thanks, it looks like the ctrl-c needs to be forwarded from nextest to child test processes, similar to how signals are forwarded on Unix. The code for that just hasn't been written yet. Would you like to contribute a patch?

from nextest.

eval-exec avatar eval-exec commented on June 12, 2024

Thanks, it looks like the ctrl-c needs to be forwarded from nextest to child test processes, similar to how signals are forwarded on Unix. The code for that just hasn't been written yet. Would you like to contribute a patch?

How to contribute a patch to this? I don't have much knowledge on windows system programming.
What Windows APIs do I need to solve this? Thank you.

from nextest.

sunshowers avatar sunshowers commented on June 12, 2024

So looking at your test further, I'm now less sure of what's going on. It looks like the test sends ctrl-c to itself (which is fine) but for some reason nextest doesn't pick up on the test exiting until 60 seconds pass. I'm not actually sure what's going on. This is going to require some debugging.

I don't have time to do this for at least the next few weeks, so any assistance would be appreciated. It's worth just digging into whether

res = child.wait() => {
// The test finished executing.
break res;
fires after 2 seconds. Also why does it take almost exactly 60 seconds? (I wonder if what's happening is that the timer firing is causing an explicit poll to happen on whether the child process has exited, when it's not being automatically woken up by the exit happening -- would be easy to verify by setting the slow timeout to something else like 30s and seeing if the test takes 30 seconds to exit).

from nextest.

ldm0 avatar ldm0 commented on June 12, 2024

I encountered the same problem. After investigation, I found that this has nothing to do with nextest.

Create a sample project:

src/main.rs:

use std::time::Duration;
use windows_sys::Win32::{
    Foundation::GetLastError,
    System::Console::{GenerateConsoleCtrlEvent, CTRL_C_EVENT},
};

fn send_ctrlc_later(duration: Duration) {
    std::thread::spawn(move || {
        std::thread::sleep(duration);

        // send CTRL_C event to myself on windows platform
        let pid = std::process::id();
        println!("send CTRL_C event to myself({}) on windows platform", pid);
        unsafe {
            GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid);
            println!("GetLastError: {}", GetLastError());
        }
    });
}

fn main() {
    let (sender, receiver) = std::sync::mpsc::channel();
    ctrlc::set_handler(move || sender.send(()).unwrap()).expect("Error setting Ctrl-C handler");

    send_ctrlc_later(Duration::from_secs(2));

    let pid = std::process::id();
    println!("Waiting for Ctrl-C: {}", pid);
    receiver.recv().unwrap();
}

Cargo.toml:

[dependencies]
ctrlc = "3.4.2"
no-panic = "0.1"
windows-sys = { version = "0.52", features = ["Win32_Foundation"] }

Run cargo test, you will see:

Waiting for Ctrl-C: 12672
send CTRL_C event to myself(12672) on windows platform
GetLastError: 0

Run cargo test > emm.txt, cargo will hang forever. You will see this in emm.txt:

Waiting for Ctrl-C: 30380
send CTRL_C event to myself(30380) on windows platform
GetLastError: 6

GetLastError returns 6, which means GenerateConsoleCtrlEvent returns ERROR_INVALID_HANDLE error. However, sending a key storke (e.g. space) in console unblocks the hang.

This is very obscure and I didn't find anything useful by googling :-(

Though GenerateConsoleCtrlEvent returns error, ctrl c signal seems to be pushed into some kind of buffer. After stdio is activated(by typing in my case, by generating slow test message in nextest case), the ctrl c signal takes effect.

from nextest.

sunshowers avatar sunshowers commented on June 12, 2024

Huh, that's really strange. So it's specifically the fact that nextest redirects standard output that causes it? I don't quite understand, to be honest! It may be worth spending some time in Process Explorer to see what's going on.

I found this thread on StackOverflow which might be related, though I'm not sure.

I am wondering if nextest can do anything here. A few things that come to mind that might, but are not guaranteed, to help:

  • create a process group on Windows
  • poke at the console in some way, maybe? I'm way out of my Windows depth here.

from nextest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.