File: no_server.rs

package info (click to toggle)
rust-interprocess 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 980 kB
  • sloc: makefile: 2
file content (26 lines) | stat: -rw-r--r-- 936 bytes parent folder | download
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
//! Tests what happens when a client attempts to connect to a local socket that doesn't exist.

use {super::util::*, anyhow::*, interprocess::local_socket::tokio::LocalSocketStream, std::io};
use std::result::Result::Ok;

pub async fn run_and_verify_error(prefer_namespaced: bool) -> TestResult {
    use io::ErrorKind::*;
    let err = match client(prefer_namespaced).await {
        Err(e) => e.downcast::<io::Error>()?,
        Ok(()) => bail!("client successfully connected to nonexistent server"),
    };
    ensure!(
        matches!(err.kind(), NotFound | ConnectionRefused),
        "expected error to be 'not found' or 'connection refused', received '{}'",
        err
    );
    Ok(())
}
async fn client(prefer_namespaced: bool) -> TestResult {
    let name = NameGen::new_auto(prefer_namespaced).next().unwrap();

    LocalSocketStream::connect(name.as_str())
        .await
        .context("Connect failed")?;
    Ok(())
}