Skip to content

Commit 24a84d5

Browse files
the10thWizSergioBenitez
authored andcommitted
Add test to validate new behavior
1 parent 0268007 commit 24a84d5

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#[macro_use] extern crate rocket;
2+
3+
use rocket::{Rocket, Build, build, fairing::AdHoc, Orbit};
4+
5+
struct AsyncDropInAsync;
6+
7+
impl Drop for AsyncDropInAsync {
8+
fn drop(&mut self) {
9+
// Attempt to fetch the current runtime while dropping
10+
// Pools in rocket_sync_db_pools (and maybe rocket_db_pools)
11+
// do use this capability. They spawn tasks to asyncronously
12+
// complete shutdown of the pool, which triggers the same panic.
13+
let _ = rocket::tokio::runtime::Handle::current();
14+
}
15+
}
16+
17+
fn rocket() -> Rocket<Build> {
18+
build().manage(AsyncDropInAsync).attach(AdHoc::on_liftoff(
19+
"Shutdown immediately",
20+
|rocket: &Rocket<Orbit>| Box::pin(async {
21+
rocket.shutdown().notify();
22+
}
23+
)))
24+
}
25+
26+
mod launch {
27+
#[launch]
28+
fn launch() -> _ {
29+
super::rocket()
30+
}
31+
#[test]
32+
fn test_launch() {
33+
main();
34+
}
35+
}
36+
37+
mod main {
38+
#[rocket::main]
39+
async fn main() {
40+
super::rocket().launch().await.unwrap();
41+
}
42+
#[test]
43+
fn test_main() {
44+
main();
45+
}
46+
#[test]
47+
fn test_execute() {
48+
rocket::execute(super::rocket().launch()).unwrap();
49+
}
50+
}

0 commit comments

Comments
 (0)