Skip to main content

xwt_tests/tests/
finished_bi_read_stream.rs

1//! This test ensures that the read stream observes the clean finish of
2//! the corresponding write side at the peer via
3//! the [`xwt_core::stream::Finished`] API.
4
5use xwt_core::prelude::*;
6
7#[derive(Debug, thiserror::Error)]
8pub enum Error<Endpoint>
9where
10    Endpoint: xwt_core::endpoint::Connect + std::fmt::Debug,
11    Endpoint::Connecting: std::fmt::Debug,
12    ConnectSessionFor<Endpoint>: xwt_core::session::stream::OpenBi + std::fmt::Debug,
13{
14    #[error("connect: {0}")]
15    Connect(#[source] xwt_error::Connect<Endpoint>),
16    #[error("open: {0}")]
17    Open(#[source] xwt_error::OpenBi<ConnectSessionFor<Endpoint>>),
18    #[error("read stream finished: {0}")]
19    ReadStreamFinished(#[source] FinishedErrorFor<RecvStreamFor<ConnectSessionFor<Endpoint>>>),
20}
21
22pub async fn run<Endpoint>(endpoint: Endpoint, url: &str) -> Result<(), Error<Endpoint>>
23where
24    Endpoint: xwt_core::endpoint::Connect + std::fmt::Debug,
25    Endpoint::Connecting: std::fmt::Debug,
26    ConnectSessionFor<Endpoint>: xwt_core::session::stream::OpenBi + std::fmt::Debug,
27{
28    let session = crate::utils::connect(&endpoint, url)
29        .await
30        .map_err(Error::Connect)?;
31
32    let (_send_stream, recv_stream) = crate::utils::open_bi(&session).await.map_err(Error::Open)?;
33
34    recv_stream
35        .finished()
36        .await
37        .map_err(Error::ReadStreamFinished)?;
38
39    Ok(())
40}