Skip to content
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

Fix potentially dropped Client in configure #40

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update integration tests to use the new API
Signed-off-by: Jiahao XU <[email protected]>
NobodyXu committed Jul 24, 2022
commit 3f5028690ccfc4897e2f0912eb35e0bdf1ccf001
6 changes: 3 additions & 3 deletions tests/client-dropped-before-command.rs
Original file line number Diff line number Diff line change
@@ -17,14 +17,14 @@ fn server() {

let mut cmd = Command::new(me);
cmd.env("I_AM_THE_CLIENT", "1");
client.configure(&mut cmd);
drop(client);

let Output {
status,
stdout: _stdout,
stderr,
} = cmd.output().unwrap();
} = client
.configure_and_run(&mut cmd, |cmd| cmd.output())
.unwrap();

assert!(status.success(), "{:#?}", String::from_utf8_lossy(&stderr));
assert_eq!(&*stderr, b"hello!\n");
7 changes: 5 additions & 2 deletions tests/client-of-myself.rs
Original file line number Diff line number Diff line change
@@ -29,9 +29,12 @@ fn server() {
let client = t!(Client::new(1));
let mut cmd = Command::new(me);
cmd.env("I_AM_THE_CLIENT", "1").stdout(Stdio::piped());
client.configure(&mut cmd);

let acq = client.acquire().unwrap();
let mut child = t!(cmd.spawn());
let mut child = client
.configure_and_run(&mut cmd, |cmd| cmd.spawn())
.unwrap();

let stdout = child.stdout.take().unwrap();
let (tx, rx) = mpsc::channel();
let t = thread::spawn(move || {
9 changes: 4 additions & 5 deletions tests/make-as-a-client.rs
Original file line number Diff line number Diff line change
@@ -62,14 +62,13 @@ bar:
.as_bytes()
));

// We're leaking one extra token to `make` sort of violating the makefile
// jobserver protocol. It has the desired effect though.
c.configure(&mut cmd);

let listener = t!(TcpListener::bind("127.0.0.1:0"));
let addr = t!(listener.local_addr());
cmd.env("TEST_ADDR", addr.to_string());
let mut child = t!(cmd.spawn());

// We're leaking one extra token to `make` sort of violating the makefile
// jobserver protocol. It has the desired effect though.
let mut child = c.configure_and_run(&mut cmd, |cmd| cmd.spawn()).unwrap();

// We should get both connections as the two programs should be run
// concurrently.
6 changes: 2 additions & 4 deletions tests/server.rs
Original file line number Diff line number Diff line change
@@ -75,8 +75,7 @@ bar:
// token", so we acquire our one token to drain the jobserver, and this
// should mean that `make` itself never has a second token available to it.
let _a = c.acquire();
c.configure(&mut cmd);
let output = t!(cmd.output());
let output = c.configure_and_run(&mut cmd, |cmd| cmd.output()).unwrap();
println!(
"\n\t=== stderr\n\t\t{}",
String::from_utf8_lossy(&output.stderr).replace("\n", "\n\t\t")
@@ -127,8 +126,7 @@ bar:

// We're leaking one extra token to `make` sort of violating the makefile
// jobserver protocol. It has the desired effect though.
c.configure(&mut cmd);
let output = t!(cmd.output());
let output = c.configure_and_run(&mut cmd, |cmd| cmd.output()).unwrap();
println!(
"\n\t=== stderr\n\t\t{}",
String::from_utf8_lossy(&output.stderr).replace("\n", "\n\t\t")