1 | #[cfg (all(tokio_unstable, feature = "tracing" ))] |
2 | mod tests { |
3 | use std::rc::Rc; |
4 | use tokio::{ |
5 | task::{Builder, LocalSet}, |
6 | test , |
7 | }; |
8 | |
9 | #[test] |
10 | async fn spawn_with_name() { |
11 | let result = Builder::new() |
12 | .name("name" ) |
13 | .spawn(async { "task executed" }) |
14 | .unwrap() |
15 | .await; |
16 | |
17 | assert_eq!(result.unwrap(), "task executed" ); |
18 | } |
19 | |
20 | #[test] |
21 | async fn spawn_blocking_with_name() { |
22 | let result = Builder::new() |
23 | .name("name" ) |
24 | .spawn_blocking(|| "task executed" ) |
25 | .unwrap() |
26 | .await; |
27 | |
28 | assert_eq!(result.unwrap(), "task executed" ); |
29 | } |
30 | |
31 | #[test] |
32 | async fn spawn_local_with_name() { |
33 | let unsend_data = Rc::new("task executed" ); |
34 | let result = LocalSet::new() |
35 | .run_until(async move { |
36 | Builder::new() |
37 | .name("name" ) |
38 | .spawn_local(async move { unsend_data }) |
39 | .unwrap() |
40 | .await |
41 | }) |
42 | .await; |
43 | |
44 | assert_eq!(*result.unwrap(), "task executed" ); |
45 | } |
46 | |
47 | #[test] |
48 | async fn spawn_without_name() { |
49 | let result = Builder::new() |
50 | .spawn(async { "task executed" }) |
51 | .unwrap() |
52 | .await; |
53 | |
54 | assert_eq!(result.unwrap(), "task executed" ); |
55 | } |
56 | |
57 | #[test] |
58 | async fn spawn_blocking_without_name() { |
59 | let result = Builder::new() |
60 | .spawn_blocking(|| "task executed" ) |
61 | .unwrap() |
62 | .await; |
63 | |
64 | assert_eq!(result.unwrap(), "task executed" ); |
65 | } |
66 | |
67 | #[test] |
68 | async fn spawn_local_without_name() { |
69 | let unsend_data = Rc::new("task executed" ); |
70 | let result = LocalSet::new() |
71 | .run_until(async move { |
72 | Builder::new() |
73 | .spawn_local(async move { unsend_data }) |
74 | .unwrap() |
75 | .await |
76 | }) |
77 | .await; |
78 | |
79 | assert_eq!(*result.unwrap(), "task executed" ); |
80 | } |
81 | } |
82 | |