|
| 1 | +// use figment::Figment; |
| 2 | +// use rocket::{custom, fairing::AdHoc, Build, Orbit, Rocket, config::SecretKey}; |
| 3 | + |
| 4 | +struct AssertDropInAsync; |
| 5 | + |
| 6 | +impl Drop for AssertDropInAsync { |
| 7 | + fn drop(&mut self) { |
| 8 | + // Attempt to fetch the current runtime while dropping |
| 9 | + // Pools in rocket_sync_db_pools (and maybe rocket_db_pools) |
| 10 | + // do use this capability. They spawn tasks to asyncronously |
| 11 | + // complete shutdown of the pool, which triggers the same panic. |
| 12 | + let _ = rocket::tokio::runtime::Handle::current(); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +// fn rocket() -> Rocket<Build> { |
| 17 | +// let mut config = rocket::Config::default(); |
| 18 | +// config.secret_key = SecretKey::generate().unwrap(); |
| 19 | +// // config.= 0; |
| 20 | +// let figment = Figment::from(config); |
| 21 | +// custom(figment).manage(AsyncDropInAsync).attach(AdHoc::on_liftoff( |
| 22 | +// "Shutdown immediately", |
| 23 | +// |rocket: &Rocket<Orbit>| { |
| 24 | +// Box::pin(async { |
| 25 | +// rocket.shutdown().notify(); |
| 26 | +// }) |
| 27 | +// }, |
| 28 | +// )) |
| 29 | +// } |
| 30 | + |
| 31 | +mod launch { |
| 32 | + use crate::prelude::*; |
| 33 | + use super::AssertDropInAsync; |
| 34 | + #[launch] |
| 35 | + fn launch() -> _ { |
| 36 | + rocket::build().manage(AssertDropInAsync) |
| 37 | + } |
| 38 | + fn run(token: (Token, ())) -> Launched { |
| 39 | + main(); |
| 40 | + token.0.ignored() |
| 41 | + } |
| 42 | + fn test_launch() -> Result<()> { |
| 43 | + let mut server = Server::spawn((), run)?; |
| 44 | + server.terminate()?; |
| 45 | + Ok(()) |
| 46 | + } |
| 47 | + register!(test_launch); |
| 48 | +} |
| 49 | + |
| 50 | +// mod main { |
| 51 | +// use rocket::tokio::net::TcpListener; |
| 52 | + |
| 53 | +// #[rocket::main] |
| 54 | +// async fn main() { |
| 55 | +// super::rocket() |
| 56 | +// .launch() |
| 57 | +// .await |
| 58 | +// .unwrap(); |
| 59 | +// } |
| 60 | +// #[test] |
| 61 | +// fn test_main() { |
| 62 | +// main(); |
| 63 | +// } |
| 64 | +// #[test] |
| 65 | +// fn test_execute() { |
| 66 | +// rocket::execute(async { |
| 67 | +// super::rocket() |
| 68 | +// .launch() |
| 69 | +// .await |
| 70 | +// .unwrap(); |
| 71 | +// }); |
| 72 | +// } |
| 73 | +// } |
0 commit comments