Skip to content

Commit

Permalink
tests: simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Aug 8, 2023
1 parent 521332e commit 933427c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions tests/unix_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,17 @@ fn unix_stream_connect() {
fn unix_stream_connect_addr() {
let (mut poll, mut events) = init_with_poll();
let barrier = Arc::new(Barrier::new(2));
let local_addr = {
// Workaround through a temporary listener using the same address,
// as there is currently no way of directly building a `SocketAddr`.
let path = temp_file("unix_stream_connect_addr");
let listener = net::UnixListener::bind(path.clone()).unwrap();
let mio_listener = mio::net::UnixListener::from_std(listener);
let address = mio_listener.local_addr().unwrap();
drop(mio_listener);
_ = std::fs::remove_file(&path);
address
};

let path = temp_file("unix_stream_connect_addr");
let listener = net::UnixListener::bind(path).unwrap();
let listener = net::UnixListener::bind(path.clone()).unwrap();
let mio_listener = mio::net::UnixListener::from_std(listener);

let local_addr = mio_listener.local_addr().unwrap();
let mut stream = UnixStream::connect_addr(&local_addr).unwrap();

let barrier_clone = barrier.clone();
let handle = thread::spawn(move || {
let (stream, _) = listener.accept().unwrap();
let (stream, _) = mio_listener.accept().unwrap();
barrier_clone.wait();
drop(stream);
});
Expand Down

0 comments on commit 933427c

Please sign in to comment.