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
36
37
38
39
40
41
use std::{pin::Pin};
use cs_utils::{random_number};
use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
create_framed_stream,
test::{test_framed_stream, test_async_stream_pinned, TestStreamMessage, TestOptions},
};
pub async fn test_stream<TAsyncDuplex: AsyncRead + AsyncWrite + Send + Unpin + ?Sized + 'static>(
channel1: Box<TAsyncDuplex>,
channel2: Box<TAsyncDuplex>,
options: TestOptions,
) -> (Pin<Box<TAsyncDuplex>>, Pin<Box<TAsyncDuplex>>) {
let stream1 = create_framed_stream::<TestStreamMessage, _>(channel1);
let stream2 = create_framed_stream::<TestStreamMessage, _>(channel2);
let framed_stream_data_len = if (options.data_len() / 128) > 16 {
options.data_len() / 128
} else {
random_number(6..=16)
};
let (stream1, stream2) = test_framed_stream(
stream1,
stream2,
options.clone()
.with_data_len(framed_stream_data_len),
).await;
return test_async_stream_pinned(
stream1.into_inner(),
stream2.into_inner(),
options,
).await;
}