Skip to content

Commit b2e3bc1

Browse files
committed
Update tests to prevent collisions
1 parent b47211c commit b2e3bc1

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

core/lib/tests/drop-in-async-context.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#[macro_use] extern crate rocket;
1+
#[macro_use]
2+
extern crate rocket;
23

3-
use rocket::{Rocket, Build, build, fairing::AdHoc, Orbit};
4+
use rocket::{build, fairing::AdHoc, Build, Orbit, Rocket};
45

56
struct AsyncDropInAsync;
67

@@ -17,10 +18,12 @@ impl Drop for AsyncDropInAsync {
1718
fn rocket() -> Rocket<Build> {
1819
build().manage(AsyncDropInAsync).attach(AdHoc::on_liftoff(
1920
"Shutdown immediately",
20-
|rocket: &Rocket<Orbit>| Box::pin(async {
21-
rocket.shutdown().notify();
22-
}
23-
)))
21+
|rocket: &Rocket<Orbit>| {
22+
Box::pin(async {
23+
rocket.shutdown().notify();
24+
})
25+
},
26+
))
2427
}
2528

2629
mod launch {
@@ -35,16 +38,26 @@ mod launch {
3538
}
3639

3740
mod main {
41+
use rocket::tokio::net::TcpListener;
42+
3843
#[rocket::main]
3944
async fn main() {
40-
super::rocket().launch().await.unwrap();
45+
super::rocket()
46+
.try_launch_on(TcpListener::bind("localhost:8001"))
47+
.await
48+
.unwrap();
4149
}
4250
#[test]
4351
fn test_main() {
4452
main();
4553
}
4654
#[test]
4755
fn test_execute() {
48-
rocket::execute(super::rocket().launch()).unwrap();
56+
rocket::execute(async {
57+
super::rocket()
58+
.try_launch_on(TcpListener::bind("localhost:8002"))
59+
.await
60+
.unwrap();
61+
});
4962
}
5063
}

0 commit comments

Comments
 (0)