1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
//! Tests what happens when a server attempts to listen for clients that never come.
use {
crate::{
local_socket::{prelude::*, ListenerNonblockingMode, ListenerOptions, Stream},
tests::util::*,
},
color_eyre::eyre::{bail, ensure},
std::io,
};
pub fn run_and_verify_error(id: &str, path: bool) -> TestResult {
use io::ErrorKind::*;
let err = match server(id, path) {
Err(e) => e,
Ok(c) => bail!("server successfully listened for a nonexistent client: {c:?}"),
};
ensure!(
matches!(err.kind(), WouldBlock),
"expected error to be 'would block', received '{}'",
err
);
Ok(())
}
fn server(id: &str, path: bool) -> io::Result<Stream> {
let listener = listen_and_pick_name(&mut namegen_local_socket(id, path), |nm| {
ListenerOptions::new()
.name(nm.borrow())
.nonblocking(ListenerNonblockingMode::Accept)
.create_sync()
})
.map_err(|e| e.downcast::<io::Error>().unwrap_or_else(io::Error::other))?
.1;
listener.accept()
}
|