use async_compat::CompatExt;
#[test]
fn the_fallback_runtime_is_built_from_the_configuration() {
async_compat::set_fallback_runtime(|builder| {
builder.worker_threads(1).thread_name("configured-runtime");
})
.unwrap();
let name = futures::executor::block_on(
async {
tokio::task::spawn_blocking(|| std::thread::current().name().map(str::to_owned))
.await
.expect("blocking task panicked")
}
.compat(),
);
assert_eq!(name.as_deref(), Some("configured-runtime"));
#[cfg(feature = "multi-thread")]
{
let (name, answer) = futures::executor::block_on(
async {
tokio::spawn(async {
let name = std::thread::current().name().map(str::to_owned);
(name, tokio::task::block_in_place(|| 42))
})
.await
.expect("spawned task panicked")
}
.compat(),
);
assert_eq!(name.as_deref(), Some("configured-runtime"));
assert_eq!(answer, 42);
}
}