use std::future::Future;
use std::task::Context;
use crate::child::spawn::windows_raw::WaitOutcome;
use crate::tokio::Command;
use crate::Stdio;
#[tokio::test]
async fn async_wait_drop_cancels_and_child_stays_waitable() {
let (started_tx, started_rx) = tokio::sync::oneshot::channel();
let (outcome_tx, outcome_rx) = tokio::sync::oneshot::channel();
let mut c = Command::new();
c.executable("findstr")
.args(["findstr", "/c:needle"])
.stdin(Stdio::pipe())
.unwrap();
let mut child = c.spawn_with_wait_observer(started_tx, outcome_tx).unwrap();
{
let mut fut = Box::pin(child.wait());
let mut cx = Context::from_waker(std::task::Waker::noop());
assert!(
fut.as_mut().poll(&mut cx).is_pending(),
"wait must park on a live, wedged child"
);
started_rx.await.expect("the blocking watcher parked");
drop(fut); }
assert_eq!(outcome_rx.await.unwrap(), WaitOutcome::Cancelled);
drop(child.stdin().expect("owned stdin writer"));
child
.wait()
.await
.expect("a fresh wait resolves after the cancelled one");
}
#[cfg(windows)]
#[tokio::test]
async fn an_async_refused_raw_spawn_does_not_clear_our_handle_inheritance() {
use crate::containment::windows::observe;
use crate::error::Error;
let mut refused = Command::new();
refused
.executable("cmd")
.args(["cmd", "/C", "exit 0"])
.contain()
.creation_flags(windows::Win32::System::Threading::CREATE_SUSPENDED.0);
observe::take_inheritance_cleared();
let err = refused.spawn().expect_err("a reserved bit must be refused");
assert!(matches!(err, Error::Unsupported { .. }), "got {err:?}");
assert!(
!observe::take_inheritance_cleared(),
"the refusal ran after the mutation it was supposed to precede"
);
let mut allowed = Command::new();
allowed.executable("cmd").args(["cmd", "/C", "exit 0"]).contain();
let mut child = allowed
.spawn()
.expect("the same command without the reserved bit spawns");
assert!(
observe::take_inheritance_cleared(),
"the seam must record a real call, else the negative leg above proves nothing"
);
child.wait().await.expect("reap");
}