xref: /aosp_15_r20/external/crosvm/base_tokio/src/tube.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2024 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #[cfg(test)]
6 mod tests {
7     use base::Tube;
8 
9     use crate::TubeTokio;
10 
11     #[tokio::test]
recv_send()12     async fn recv_send() {
13         let (a, b) = Tube::pair().unwrap();
14         let mut b = TubeTokio::new(b).unwrap();
15 
16         let blocking_task = tokio::task::spawn_blocking(move || {
17             a.send(&5u8).unwrap();
18             a.recv::<u8>().unwrap()
19         });
20 
21         assert_eq!(b.recv::<u8>().await.unwrap(), 5u8);
22         b.send(&16u8).await.unwrap();
23         assert_eq!(blocking_task.await.unwrap(), 16u8);
24     }
25 }
26