| 1 |
#![allow(unknown_lints, unexpected_cfgs)] |
| 2 |
#![cfg(all(tokio_unstable, feature = "tracing"))] |
| 3 |
|
| 4 |
use std::rc::Rc; |
| 5 |
use tokio::{ |
| 6 |
task::{Builder, LocalSet}, |
| 7 |
test, |
| 8 |
}; |
| 9 |
|
| 10 |
#[test] |
| 11 |
async fn spawn_with_name() { |
| 12 |
let result = Builder::new() |
| 13 |
.name("name") |
| 14 |
.spawn(async { "task executed" }) |
| 15 |
.unwrap() |
| 16 |
.await; |
| 17 |
|
| 18 |
assert_eq!(result.unwrap(), "task executed"); |
| 19 |
} |
| 20 |
|
| 21 |
#[test] |
| 22 |
async fn spawn_blocking_with_name() { |
| 23 |
let result = Builder::new() |
| 24 |
.name("name") |
| 25 |
.spawn_blocking(|| "task executed") |
| 26 |
.unwrap() |
| 27 |
.await; |
| 28 |
|
| 29 |
assert_eq!(result.unwrap(), "task executed"); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
async fn spawn_local_with_name() { |
| 34 |
let unsend_data = Rc::new("task executed"); |
| 35 |
let result = LocalSet::new() |
| 36 |
.run_until(async move { |
| 37 |
Builder::new() |
| 38 |
.name("name") |
| 39 |
.spawn_local(async move { unsend_data }) |
| 40 |
.unwrap() |
| 41 |
.await |
| 42 |
}) |
| 43 |
.await; |
| 44 |
|
| 45 |
assert_eq!(*result.unwrap(), "task executed"); |
| 46 |
} |
| 47 |
|
| 48 |
#[test] |
| 49 |
async fn spawn_without_name() { |
| 50 |
let result = Builder::new() |
| 51 |
.spawn(async { "task executed" }) |
| 52 |
.unwrap() |
| 53 |
.await; |
| 54 |
|
| 55 |
assert_eq!(result.unwrap(), "task executed"); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
async fn spawn_blocking_without_name() { |
| 60 |
let result = Builder::new() |
| 61 |
.spawn_blocking(|| "task executed") |
| 62 |
.unwrap() |
| 63 |
.await; |
| 64 |
|
| 65 |
assert_eq!(result.unwrap(), "task executed"); |
| 66 |
} |
| 67 |
|
| 68 |
#[test] |
| 69 |
async fn spawn_local_without_name() { |
| 70 |
let unsend_data = Rc::new("task executed"); |
| 71 |
let result = LocalSet::new() |
| 72 |
.run_until(async move { |
| 73 |
Builder::new() |
| 74 |
.spawn_local(async move { unsend_data }) |
| 75 |
.unwrap() |
| 76 |
.await |
| 77 |
}) |
| 78 |
.await; |
| 79 |
|
| 80 |
assert_eq!(*result.unwrap(), "task executed"); |
| 81 |
} |