Skip to content

Commit

Permalink
cat: make tests stable (#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
rethab authored Apr 22, 2021
1 parent fb2ae04 commit b756b98
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,22 +400,29 @@ fn test_domain_socket() {
use std::thread;
use tempdir::TempDir;
use unix_socket::UnixListener;
use std::sync::{Barrier, Arc};

let dir = TempDir::new("unix_socket").expect("failed to create dir");
let socket_path = dir.path().join("sock");
let listener = UnixListener::bind(&socket_path).expect("failed to create socket");

// use a barrier to ensure we don't run cat before the listener is setup
let barrier = Arc::new(Barrier::new(2));
let barrier2 = Arc::clone(&barrier);

let thread = thread::spawn(move || {
let mut stream = listener.accept().expect("failed to accept connection").0;
barrier2.wait();
stream
.write_all(b"a\tb")
.expect("failed to write test data");
});

new_ucmd!()
.args(&[socket_path])
.succeeds()
.stdout_only("a\tb");
let child = new_ucmd!().args(&[socket_path]).run_no_wait();
barrier.wait();
let stdout = &child.wait_with_output().unwrap().stdout.clone();
let output = String::from_utf8_lossy(&stdout);
assert_eq!("a\tb", output);

thread.join().unwrap();
}

0 comments on commit b756b98

Please sign in to comment.