Skip to content

Commit a828b76

Browse files
committed
Add (non-functional) testbench test
1 parent 8742c65 commit a828b76

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

testbench/src/server.rs

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ impl Token {
152152
pub fn launch(self, rocket: Rocket<Build>) -> Launched {
153153
self.launch_with::<DefaultListener>(rocket)
154154
}
155+
156+
pub fn ignored(self) -> Launched {
157+
Launched(())
158+
}
155159
}
156160

157161
impl Drop for Server {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
// }

testbench/src/servers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub mod mtls;
66
pub mod sni_resolver;
77
pub mod tracing;
88
pub mod tls;
9+
pub mod drop_in_async_context;

0 commit comments

Comments
 (0)