-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acac38a
commit b47211c
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#[macro_use] extern crate rocket; | ||
|
||
use rocket::{Rocket, Build, build, fairing::AdHoc, Orbit}; | ||
|
||
struct AsyncDropInAsync; | ||
|
||
impl Drop for AsyncDropInAsync { | ||
fn drop(&mut self) { | ||
// Attempt to fetch the current runtime while dropping | ||
// Pools in rocket_sync_db_pools (and maybe rocket_db_pools) | ||
// do use this capability. They spawn tasks to asyncronously | ||
// complete shutdown of the pool, which triggers the same panic. | ||
let _ = rocket::tokio::runtime::Handle::current(); | ||
} | ||
} | ||
|
||
fn rocket() -> Rocket<Build> { | ||
build().manage(AsyncDropInAsync).attach(AdHoc::on_liftoff( | ||
"Shutdown immediately", | ||
|rocket: &Rocket<Orbit>| Box::pin(async { | ||
rocket.shutdown().notify(); | ||
} | ||
))) | ||
} | ||
|
||
mod launch { | ||
#[launch] | ||
fn launch() -> _ { | ||
super::rocket() | ||
} | ||
#[test] | ||
fn test_launch() { | ||
main(); | ||
} | ||
} | ||
|
||
mod main { | ||
#[rocket::main] | ||
async fn main() { | ||
super::rocket().launch().await.unwrap(); | ||
} | ||
#[test] | ||
fn test_main() { | ||
main(); | ||
} | ||
#[test] | ||
fn test_execute() { | ||
rocket::execute(super::rocket().launch()).unwrap(); | ||
} | ||
} |