Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: add panic string to debug/display output of JoinError #6753

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
task: don't assert task ID in tests for JoinError debug and display…
… output
abonander committed Aug 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit af5e9f203278e4ad433e392140e697c073c9296c
58 changes: 44 additions & 14 deletions tokio/tests/task_abort.rs
Original file line number Diff line number Diff line change
@@ -238,27 +238,42 @@ fn test_join_error_display() {
.await
.unwrap_err();

assert_eq!(
join_err.to_string(),
"task 1 panicked with message \"Format-args payload: 1234\""
// We can't assert the full output because the task ID can change.
let join_err_str = join_err.to_string();

assert!(
join_err_str.starts_with("task ")
&& join_err_str.ends_with(" panicked with message \"Format-args payload: 1234\""),
"Unexpected join_err_str {:?}",
join_err_str
);

// `&'static str` payload
let join_err = tokio::spawn(async move { panic!("Const payload") })
.await
.unwrap_err();

assert_eq!(
join_err.to_string(),
"task 2 panicked with message \"Const payload\""
let join_err_str = join_err.to_string();

assert!(
join_err_str.starts_with("task ")
&& join_err_str.ends_with(" panicked with message \"Const payload\""),
"Unexpected join_err_str {:?}",
join_err_str
);

// Non-string payload
let join_err = tokio::spawn(async move { std::panic::panic_any(1234i32) })
.await
.unwrap_err();

assert_eq!(join_err.to_string(), "task 3 panicked");
let join_err_str = join_err.to_string();

assert!(
join_err_str.starts_with("task ") && join_err_str.ends_with(" panicked"),
"Unexpected join_err_str {:?}",
join_err_str
);
});
}

@@ -277,26 +292,41 @@ fn test_join_error_debug() {
.await
.unwrap_err();

assert_eq!(
format!("{:?}", join_err),
"JoinError::Panic(Id(1), \"Format-args payload: 1234\", ...)"
// We can't assert the full output because the task ID can change.
let join_err_str = format!("{:?}", join_err);

assert!(
join_err_str.starts_with("JoinError::Panic(Id(")
&& join_err_str.ends_with("), \"Format-args payload: 1234\", ...)"),
"Unexpected join_err_str {:?}",
join_err_str
);

// `&'static str` payload
let join_err = tokio::spawn(async move { panic!("Const payload") })
.await
.unwrap_err();

assert_eq!(
format!("{:?}", join_err),
"JoinError::Panic(Id(2), \"Const payload\", ...)"
let join_err_str = format!("{:?}", join_err);

assert!(
join_err_str.starts_with("JoinError::Panic(Id(")
&& join_err_str.ends_with("), \"Const payload\", ...)"),
"Unexpected join_err_str {:?}",
join_err_str
);

// Non-string payload
let join_err = tokio::spawn(async move { std::panic::panic_any(1234i32) })
.await
.unwrap_err();

assert_eq!(format!("{:?}", join_err), "JoinError::Panic(Id(3), ...)");
let join_err_str = format!("{:?}", join_err);

assert!(
join_err_str.starts_with("JoinError::Panic(Id(") && join_err_str.ends_with("), ...)"),
"Unexpected join_err_str {:?}",
join_err_str
);
});
}