@@ -2,8 +2,8 @@ use super::common::*;
22use crate :: * ;
33use log:: * ;
44use rstest:: * ;
5- use std:: sync:: Arc ;
65use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
6+ use std:: sync:: Arc ;
77use std:: thread;
88use std:: time:: Duration ;
99
@@ -49,6 +49,58 @@ async fn test_basic_1_tx_async_1_rx_blocking<T: AsyncTxTrait<usize>, R: Blocking
4949 rt. shutdown_background ( ) ; // Prevent panic on runtime drop
5050}
5151
52+ #[ rstest]
53+ #[ case( spsc:: bounded_tx_async_rx_blocking:: <usize >( 100 ) ) ]
54+ #[ case( mpsc:: bounded_tx_async_rx_blocking:: <usize >( 100 ) ) ]
55+ #[ case( mpmc:: bounded_tx_async_rx_blocking:: <usize >( 100 ) ) ]
56+ #[ tokio:: test]
57+ async fn test_timeout_1_tx_async_1_rx_blocking <
58+ T : AsyncTxTrait < usize > ,
59+ R : BlockingRxTrait < usize > ,
60+ > (
61+ setup_log : ( ) , #[ case] channel : ( T , R ) ,
62+ ) {
63+ let _ = setup_log; // Disable unused var warning
64+ let ( tx, rx) = channel;
65+
66+ let rx_res = rx. try_recv ( ) ;
67+ assert ! ( rx_res. is_err( ) ) ;
68+ assert ! ( rx_res. unwrap_err( ) . is_empty( ) ) ;
69+ let batch_1: usize = 100 ;
70+ let batch_2: usize = 200 ;
71+ let rt = get_runtime ( ) ;
72+ rt. spawn ( async move {
73+ for i in 0 ..batch_1 {
74+ let tx_res = tx. send ( i) . await ;
75+ assert ! ( tx_res. is_ok( ) ) ;
76+ }
77+ for i in batch_1..( batch_1 + batch_2) {
78+ assert ! ( tx. send( 10 + i) . await . is_ok( ) ) ;
79+ tokio:: time:: sleep ( Duration :: from_millis ( 2 ) ) . await ;
80+ }
81+
82+ tokio:: time:: sleep ( Duration :: from_millis ( 200 ) ) . await ;
83+ assert ! ( tx. send( 123 ) . await . is_ok( ) ) ;
84+ } ) ;
85+ for _ in 0 ..( batch_1 + batch_2) {
86+ match rx. recv ( ) {
87+ Ok ( i) => {
88+ debug ! ( "recv {}" , i) ;
89+ }
90+ Err ( e) => {
91+ panic ! ( "error {}" , e) ;
92+ }
93+ }
94+ }
95+
96+ assert ! ( rx. recv_timeout( Duration :: from_millis( 100 ) ) . is_err( ) ) ;
97+ assert ! ( rx. recv_timeout( Duration :: from_millis( 200 ) ) . is_ok( ) ) ;
98+
99+ let res = rx. recv ( ) ;
100+ assert ! ( res. is_err( ) ) ;
101+ rt. shutdown_background ( ) ; // Prevent panic on runtime drop
102+ }
103+
52104#[ rstest]
53105#[ case( mpsc:: bounded_tx_async_rx_blocking:: <usize >( 10 ) , 8 ) ]
54106#[ case( mpsc:: bounded_tx_async_rx_blocking:: <usize >( 10 ) , 100 ) ]
0 commit comments