mirror of https://github.com/rwf2/Rocket.git
Use threaded scheduler in tests.
This prevents async I/O timeouts in attach fairings. Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
This commit is contained in:
parent
0c150c2a0e
commit
8570afff3e
|
@ -166,7 +166,9 @@ pub fn custom<T: figment::Provider>(provider: T) -> Rocket {
|
|||
#[doc(hidden)]
|
||||
pub fn async_test<R>(fut: impl std::future::Future<Output = R> + Send) -> R {
|
||||
tokio::runtime::Builder::new()
|
||||
.basic_scheduler()
|
||||
.threaded_scheduler()
|
||||
.thread_name("rocket-test-worker-thread")
|
||||
.core_threads(1)
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("create tokio runtime")
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#[rocket::async_test]
|
||||
async fn test_await_timer_inside_attach() {
|
||||
|
||||
async fn do_async_setup() {
|
||||
// By using a timer or I/O resource, we ensure that do_async_setup will
|
||||
// deadlock if no thread is able to tick the time or I/O drivers.
|
||||
rocket::tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
}
|
||||
|
||||
rocket::ignite()
|
||||
.attach(rocket::fairing::AdHoc::on_attach("1", |rocket| async {
|
||||
do_async_setup().await;
|
||||
Ok(rocket)
|
||||
}));
|
||||
}
|
Loading…
Reference in New Issue