summaryrefslogtreecommitdiffstats
path: root/vendor/tokio/tests/dump.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/dump.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/dump.rs')
-rw-r--r--vendor/tokio/tests/dump.rs99
1 files changed, 99 insertions, 0 deletions
diff --git a/vendor/tokio/tests/dump.rs b/vendor/tokio/tests/dump.rs
new file mode 100644
index 000000000..658ee4b9b
--- /dev/null
+++ b/vendor/tokio/tests/dump.rs
@@ -0,0 +1,99 @@
+#![cfg(all(
+ tokio_unstable,
+ tokio_taskdump,
+ target_os = "linux",
+ any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
+))]
+
+use std::hint::black_box;
+use tokio::runtime::{self, Handle};
+
+#[inline(never)]
+async fn a() {
+ black_box(b()).await
+}
+
+#[inline(never)]
+async fn b() {
+ black_box(c()).await
+}
+
+#[inline(never)]
+async fn c() {
+ loop {
+ black_box(tokio::task::yield_now()).await
+ }
+}
+
+#[test]
+fn current_thread() {
+ let rt = runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .unwrap();
+
+ async fn dump() {
+ let handle = Handle::current();
+ let dump = handle.dump().await;
+
+ let tasks: Vec<_> = dump.tasks().iter().collect();
+
+ assert_eq!(tasks.len(), 3);
+
+ for task in tasks {
+ let trace = task.trace().to_string();
+ eprintln!("\n\n{trace}\n\n");
+ assert!(trace.contains("dump::a"));
+ assert!(trace.contains("dump::b"));
+ assert!(trace.contains("dump::c"));
+ assert!(trace.contains("tokio::task::yield_now"));
+ }
+ }
+
+ rt.block_on(async {
+ tokio::select!(
+ biased;
+ _ = tokio::spawn(a()) => {},
+ _ = tokio::spawn(a()) => {},
+ _ = tokio::spawn(a()) => {},
+ _ = dump() => {},
+ );
+ });
+}
+
+#[test]
+fn multi_thread() {
+ let rt = runtime::Builder::new_multi_thread()
+ .enable_all()
+ .worker_threads(3)
+ .build()
+ .unwrap();
+
+ async fn dump() {
+ let handle = Handle::current();
+ let dump = handle.dump().await;
+
+ let tasks: Vec<_> = dump.tasks().iter().collect();
+
+ assert_eq!(tasks.len(), 3);
+
+ for task in tasks {
+ let trace = task.trace().to_string();
+ eprintln!("\n\n{trace}\n\n");
+ assert!(trace.contains("dump::a"));
+ assert!(trace.contains("dump::b"));
+ assert!(trace.contains("dump::c"));
+ assert!(trace.contains("tokio::task::yield_now"));
+ }
+ }
+
+ rt.block_on(async {
+ tokio::select!(
+ biased;
+ _ = tokio::spawn(a()) => {},
+ _ = tokio::spawn(a()) => {},
+ _ = tokio::spawn(a()) => {},
+ _ = dump() => {},
+ );
+ });
+}