summaryrefslogtreecommitdiffstats
path: root/vendor/tokio/tests/rt_handle.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/tokio/tests/rt_handle.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tokio/tests/rt_handle.rs')
-rw-r--r--vendor/tokio/tests/rt_handle.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/tokio/tests/rt_handle.rs b/vendor/tokio/tests/rt_handle.rs
new file mode 100644
index 000000000..34c99cdae
--- /dev/null
+++ b/vendor/tokio/tests/rt_handle.rs
@@ -0,0 +1,67 @@
+#![warn(rust_2018_idioms)]
+#![cfg(feature = "full")]
+
+use tokio::runtime::Runtime;
+
+#[test]
+fn basic_enter() {
+ let rt1 = rt();
+ let rt2 = rt();
+
+ let enter1 = rt1.enter();
+ let enter2 = rt2.enter();
+
+ drop(enter2);
+ drop(enter1);
+}
+
+#[test]
+#[should_panic]
+fn interleave_enter_different_rt() {
+ let rt1 = rt();
+ let rt2 = rt();
+
+ let enter1 = rt1.enter();
+ let enter2 = rt2.enter();
+
+ drop(enter1);
+ drop(enter2);
+}
+
+#[test]
+#[should_panic]
+fn interleave_enter_same_rt() {
+ let rt1 = rt();
+
+ let _enter1 = rt1.enter();
+ let enter2 = rt1.enter();
+ let enter3 = rt1.enter();
+
+ drop(enter2);
+ drop(enter3);
+}
+
+#[test]
+#[cfg(not(tokio_wasi))]
+fn interleave_then_enter() {
+ let _ = std::panic::catch_unwind(|| {
+ let rt1 = rt();
+ let rt2 = rt();
+
+ let enter1 = rt1.enter();
+ let enter2 = rt2.enter();
+
+ drop(enter1);
+ drop(enter2);
+ });
+
+ // Can still enter
+ let rt3 = rt();
+ let _enter = rt3.enter();
+}
+
+fn rt() -> Runtime {
+ tokio::runtime::Builder::new_current_thread()
+ .build()
+ .unwrap()
+}