1 | #![warn (rust_2018_idioms)] |
2 | #![cfg (feature = "full" )] |
3 | |
4 | use tokio::runtime::Runtime; |
5 | |
6 | #[cfg (panic = "unwind" )] |
7 | #[test] |
8 | fn basic_enter() { |
9 | let rt1 = rt(); |
10 | let rt2 = rt(); |
11 | |
12 | let enter1 = rt1.enter(); |
13 | let enter2 = rt2.enter(); |
14 | |
15 | drop(enter2); |
16 | drop(enter1); |
17 | } |
18 | |
19 | #[cfg (panic = "unwind" )] |
20 | #[test] |
21 | #[should_panic ] |
22 | fn interleave_enter_different_rt() { |
23 | let rt1 = rt(); |
24 | let rt2 = rt(); |
25 | |
26 | let enter1 = rt1.enter(); |
27 | let enter2 = rt2.enter(); |
28 | |
29 | drop(enter1); |
30 | drop(enter2); |
31 | } |
32 | |
33 | #[cfg (panic = "unwind" )] |
34 | #[test] |
35 | #[should_panic ] |
36 | fn interleave_enter_same_rt() { |
37 | let rt1 = rt(); |
38 | |
39 | let _enter1 = rt1.enter(); |
40 | let enter2 = rt1.enter(); |
41 | let enter3 = rt1.enter(); |
42 | |
43 | drop(enter2); |
44 | drop(enter3); |
45 | } |
46 | |
47 | #[cfg (panic = "unwind" )] |
48 | #[test] |
49 | #[cfg (not(target_os = "wasi" ))] |
50 | fn interleave_then_enter() { |
51 | let _ = std::panic::catch_unwind(|| { |
52 | let rt1 = rt(); |
53 | let rt2 = rt(); |
54 | |
55 | let enter1 = rt1.enter(); |
56 | let enter2 = rt2.enter(); |
57 | |
58 | drop(enter1); |
59 | drop(enter2); |
60 | }); |
61 | |
62 | // Can still enter |
63 | let rt3 = rt(); |
64 | let _enter = rt3.enter(); |
65 | } |
66 | |
67 | #[cfg (tokio_unstable)] |
68 | mod unstable { |
69 | use super::*; |
70 | |
71 | #[test] |
72 | fn runtime_id_is_same() { |
73 | let rt = rt(); |
74 | |
75 | let handle1 = rt.handle(); |
76 | let handle2 = rt.handle(); |
77 | |
78 | assert_eq!(handle1.id(), handle2.id()); |
79 | } |
80 | |
81 | #[test] |
82 | fn runtime_ids_different() { |
83 | let rt1 = rt(); |
84 | let rt2 = rt(); |
85 | |
86 | assert_ne!(rt1.handle().id(), rt2.handle().id()); |
87 | } |
88 | } |
89 | |
90 | fn rt() -> Runtime { |
91 | tokio::runtime::Builder::new_current_thread() |
92 | .build() |
93 | .unwrap() |
94 | } |
95 | |