xref: /tonic/tests/integration_tests/src/lib.rs (revision ff71e893)
1 pub mod pb {
2     tonic::include_proto!("test");
3     tonic::include_proto!("stream");
4 }
5 
6 pub mod mock {
7     use std::{
8         io::IoSlice,
9         pin::Pin,
10         task::{Context, Poll},
11     };
12 
13     use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
14     use tonic::transport::server::Connected;
15 
16     #[derive(Debug)]
17     pub struct MockStream(pub tokio::io::DuplexStream);
18 
19     impl Connected for MockStream {
20         type ConnectInfo = ();
21 
22         /// Create type holding information about the connection.
connect_info(&self) -> Self::ConnectInfo23         fn connect_info(&self) -> Self::ConnectInfo {}
24     }
25 
26     impl AsyncRead for MockStream {
poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<std::io::Result<()>>27         fn poll_read(
28             mut self: Pin<&mut Self>,
29             cx: &mut Context<'_>,
30             buf: &mut ReadBuf<'_>,
31         ) -> Poll<std::io::Result<()>> {
32             Pin::new(&mut self.0).poll_read(cx, buf)
33         }
34     }
35 
36     impl AsyncWrite for MockStream {
poll_write( mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<std::io::Result<usize>>37         fn poll_write(
38             mut self: Pin<&mut Self>,
39             cx: &mut Context<'_>,
40             buf: &[u8],
41         ) -> Poll<std::io::Result<usize>> {
42             Pin::new(&mut self.0).poll_write(cx, buf)
43         }
44 
poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>45         fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
46             Pin::new(&mut self.0).poll_flush(cx)
47         }
48 
poll_shutdown( mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<std::io::Result<()>>49         fn poll_shutdown(
50             mut self: Pin<&mut Self>,
51             cx: &mut Context<'_>,
52         ) -> Poll<std::io::Result<()>> {
53             Pin::new(&mut self.0).poll_shutdown(cx)
54         }
55 
poll_write_vectored( mut self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, std::io::Error>>56         fn poll_write_vectored(
57             mut self: Pin<&mut Self>,
58             cx: &mut Context<'_>,
59             bufs: &[IoSlice<'_>],
60         ) -> Poll<Result<usize, std::io::Error>> {
61             Pin::new(&mut self.0).poll_write_vectored(cx, bufs)
62         }
63 
is_write_vectored(&self) -> bool64         fn is_write_vectored(&self) -> bool {
65             self.0.is_write_vectored()
66         }
67     }
68 }
69 
trace_init()70 pub fn trace_init() {
71     let _ = tracing_subscriber::fmt::try_init();
72 }
73 
74 pub type BoxFuture<'a, T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send + 'a>>;
75