Skip to content

Commit 5e271d7

Browse files
committed
tests: alter integration tests for stdio to not use a handrolled cat implementation
This fixes #4801, where, as a result of rust-lang/rust#95469, our implementation of cat used for this test no longer works, as stdio functions on windows now can abort the process if the pipe is set to nonblocking mode. Unfortunately in windows, setting one end of the pipe to be nonblocking makes the whole thing nonblocking, so when, in tokio::process we set the child pipes to nonblocking mode, it causes serious problems for any rust program at the other end. Fixing this issue is for another day, but fixing the tests is for today.
1 parent 8ed06ef commit 5e271d7

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

tests-integration/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77

88
[[bin]]
99
name = "test-cat"
10+
required-features = ["rt-process-io-util"]
1011

1112
[[bin]]
1213
name = "test-mem"
@@ -17,6 +18,7 @@ name = "test-process-signal"
1718
required-features = ["rt-process-signal"]
1819

1920
[features]
21+
rt-process-io-util = ["tokio/rt", "tokio/macros", "tokio/process", "tokio/io-util", "tokio/io-std"]
2022
# For mem check
2123
rt-net = ["tokio/rt", "tokio/rt-multi-thread", "tokio/net"]
2224
# For test-process-signal

tests-integration/src/bin/test-cat.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
//! A cat-like utility that can be used as a subprocess to test I/O
22
//! stream communication.
33
4-
use std::io;
5-
use std::io::Write;
4+
use tokio::io::AsyncWriteExt;
65

7-
fn main() {
8-
let stdin = io::stdin();
9-
let mut stdout = io::stdout();
10-
let mut line = String::new();
11-
loop {
12-
line.clear();
13-
stdin.read_line(&mut line).unwrap();
14-
if line.is_empty() {
15-
break;
16-
}
17-
stdout.write_all(line.as_bytes()).unwrap();
18-
}
19-
stdout.flush().unwrap();
6+
#[tokio::main(flavor = "current_thread")]
7+
async fn main() {
8+
let mut stdin = tokio::io::stdin();
9+
let mut stdout = tokio::io::stdout();
10+
11+
tokio::io::copy(&mut stdin, &mut stdout).await.unwrap();
12+
13+
stdout.flush().await.unwrap();
2014
}

tests-integration/tests/process_stdio.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ use tokio_test::assert_ok;
88

99
use futures::future::{self, FutureExt};
1010
use std::convert::TryInto;
11-
use std::env;
1211
use std::io;
1312
use std::process::{ExitStatus, Stdio};
1413

14+
// so, we need to change this back as a test, but for now this doesn't work because of:
15+
// https://github.com/rust-lang/rust/pull/95469
16+
//
17+
// undo when this is closed: https://github.com/tokio-rs/tokio/issues/4802
18+
19+
// fn cat() -> Command {
20+
// let mut cmd = Command::new(std::env!("CARGO_BIN_EXE_test-cat"));
21+
// cmd.stdin(Stdio::piped()).stdout(Stdio::piped());
22+
// cmd
23+
// }
24+
1525
fn cat() -> Command {
16-
let mut cmd = Command::new(env!("CARGO_BIN_EXE_test-cat"));
26+
let mut cmd = Command::new("cat");
1727
cmd.stdin(Stdio::piped()).stdout(Stdio::piped());
1828
cmd
1929
}

0 commit comments

Comments
 (0)