1 #![allow(clippy::blacklisted_name)]
2 use tokio::sync::oneshot;
3 use tokio_test::{assert_pending, assert_ready, task};
4
5 #[tokio::test]
sync_one_lit_expr_comma()6 async fn sync_one_lit_expr_comma() {
7 let foo = tokio::join!(async { 1 },);
8
9 assert_eq!(foo, (1,));
10 }
11
12 #[tokio::test]
sync_one_lit_expr_no_comma()13 async fn sync_one_lit_expr_no_comma() {
14 let foo = tokio::join!(async { 1 });
15
16 assert_eq!(foo, (1,));
17 }
18
19 #[tokio::test]
sync_two_lit_expr_comma()20 async fn sync_two_lit_expr_comma() {
21 let foo = tokio::join!(async { 1 }, async { 2 },);
22
23 assert_eq!(foo, (1, 2));
24 }
25
26 #[tokio::test]
sync_two_lit_expr_no_comma()27 async fn sync_two_lit_expr_no_comma() {
28 let foo = tokio::join!(async { 1 }, async { 2 });
29
30 assert_eq!(foo, (1, 2));
31 }
32
33 #[tokio::test]
two_await()34 async fn two_await() {
35 let (tx1, rx1) = oneshot::channel::<&str>();
36 let (tx2, rx2) = oneshot::channel::<u32>();
37
38 let mut join = task::spawn(async {
39 tokio::join!(async { rx1.await.unwrap() }, async { rx2.await.unwrap() })
40 });
41
42 assert_pending!(join.poll());
43
44 tx2.send(123).unwrap();
45 assert!(join.is_woken());
46 assert_pending!(join.poll());
47
48 tx1.send("hello").unwrap();
49 assert!(join.is_woken());
50 let res = assert_ready!(join.poll());
51
52 assert_eq!(("hello", 123), res);
53 }
54
55 #[test]
join_size()56 fn join_size() {
57 use futures::future;
58 use std::mem;
59
60 let fut = async {
61 let ready = future::ready(0i32);
62 tokio::join!(ready)
63 };
64 assert_eq!(mem::size_of_val(&fut), 16);
65
66 let fut = async {
67 let ready1 = future::ready(0i32);
68 let ready2 = future::ready(0i32);
69 tokio::join!(ready1, ready2)
70 };
71 assert_eq!(mem::size_of_val(&fut), 28);
72 }
73