Skip to content

Commit

Permalink
move panic functions to their file
Browse files Browse the repository at this point in the history
  • Loading branch information
agayev committed Nov 12, 2022
1 parent 942106f commit 7a12177
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 35 deletions.
35 changes: 0 additions & 35 deletions tokio/tests/task_id.rs
Expand Up @@ -12,12 +12,6 @@ use tokio::runtime::{Builder, Runtime};
use tokio::sync::oneshot;
use tokio::task::{self, Id, LocalSet};

mod support {
pub mod panic;
}
#[cfg(not(tokio_wasi))]
use support::panic::test_panic;

#[tokio::test(flavor = "current_thread")]
async fn task_id_spawn() {
tokio::spawn(async { println!("task id: {}", task::id()) })
Expand Down Expand Up @@ -271,32 +265,3 @@ async fn task_id_block_in_place_block_on_spawn() {
.await
.unwrap();
}

#[cfg(not(tokio_wasi))]
#[test]
fn task_id_outside_task_panic_caller() -> Result<(), Box<dyn Error>> {
let panic_location_file = test_panic(|| {
let _ = task::id();
});

// The panic location should be in this file
assert_eq!(&panic_location_file.unwrap(), file!());

Ok(())
}

#[cfg(not(tokio_wasi))]
#[test]
fn task_id_inside_block_on_panic_caller() -> Result<(), Box<dyn Error>> {
let panic_location_file = test_panic(|| {
let rt = Runtime::new().unwrap();
rt.block_on(async {
task::id();
});
});

// The panic location should be in this file
assert_eq!(&panic_location_file.unwrap(), file!());

Ok(())
}
27 changes: 27 additions & 0 deletions tokio/tests/task_panic.rs
Expand Up @@ -121,3 +121,30 @@ fn local_key_get_panic_caller() -> Result<(), Box<dyn Error>> {

Ok(())
}

#[test]
fn task_id_outside_task_panic_caller() -> Result<(), Box<dyn Error>> {
let panic_location_file = test_panic(|| {
let _ = task::id();
});

// The panic location should be in this file
assert_eq!(&panic_location_file.unwrap(), file!());

Ok(())
}

#[test]
fn task_id_inside_block_on_panic_caller() -> Result<(), Box<dyn Error>> {
let panic_location_file = test_panic(|| {
let rt = Runtime::new().unwrap();
rt.block_on(async {
task::id();
});
});

// The panic location should be in this file
assert_eq!(&panic_location_file.unwrap(), file!());

Ok(())
}

0 comments on commit 7a12177

Please sign in to comment.