Skip to content

Commit

Permalink
add more tests -- one to go
Browse files Browse the repository at this point in the history
  • Loading branch information
agayev committed Nov 9, 2022
1 parent 82cc448 commit 370e754
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions tokio/tests/task_local.rs
Expand Up @@ -193,7 +193,7 @@ async fn task_ids_match_multi_thread() {
async fn task_id_future_destructor_completion() {
use tokio::task;

struct MyFuture {}
struct MyFuture;
impl Future for MyFuture {
type Output = ();

Expand All @@ -207,15 +207,15 @@ async fn task_id_future_destructor_completion() {
}
}

tokio::spawn(MyFuture {}).await.unwrap();
tokio::spawn(MyFuture).await.unwrap();
}

#[cfg(tokio_unstable)]
#[tokio::test(flavor = "multi_thread")]
async fn task_id_future_destructor_abort() {
use tokio::task;

struct MyFuture {}
struct MyFuture;
impl Future for MyFuture {
type Output = ();

Expand All @@ -229,18 +229,53 @@ async fn task_id_future_destructor_abort() {
}
}

tokio::spawn(MyFuture {}).abort();
tokio::spawn(MyFuture).abort();
}

#[cfg(tokio_unstable)]
#[tokio::test(flavor = "current_thread")]
async fn task_id_output_destructor_handle_dropped_before_completion() {
use tokio::task;

struct MyOutput;
impl Drop for MyOutput {
fn drop(&mut self) {
println!("task id: {}", task::id());
}
}

struct MyFuture {
tx: Option<oneshot::Sender<()>>,
}
impl Future for MyFuture {
type Output = MyOutput;

fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
let _ = self.tx.take().unwrap().send(());
Poll::Ready(MyOutput)
}
}
impl Drop for MyFuture {
fn drop(&mut self) {
println!("task id: {}", task::id());
}
}

let (tx, rx) = oneshot::channel();
let handle = tokio::spawn(MyFuture { tx: Some(tx) });
drop(handle);
rx.await.unwrap();
}

#[cfg(tokio_unstable)]
#[tokio::test(flavor = "current_thread")]
async fn task_id_output_destructor_handle_dropped_after_completion() {
use tokio::task;

struct MyOutput {}
struct MyOutput;
impl Drop for MyOutput {
fn drop(&mut self) {
println!("output task id: {}", task::id());
println!("task id: {}", task::id());
}
}

Expand All @@ -252,12 +287,12 @@ async fn task_id_output_destructor_handle_dropped_after_completion() {

fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
let _ = self.tx.take().unwrap().send(());
Poll::Ready(MyOutput {})
Poll::Ready(MyOutput)
}
}
impl Drop for MyFuture {
fn drop(&mut self) {
println!("future task id: {}", task::id());
println!("task id: {}", task::id());
}
}

Expand Down

0 comments on commit 370e754

Please sign in to comment.