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