Skip to content

Commit 6ce8280

Browse files
the10thWizSergioBenitez
authored andcommitted
Update tests to use unnumbered ports
1 parent aa208c7 commit 6ce8280

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[macro_use]
22
extern crate rocket;
33

4-
use figment::Figment;
5-
use rocket::{custom, fairing::AdHoc, Build, Orbit, Rocket, config::SecretKey};
4+
use rocket::figment::{providers::{Format as _, Toml}, Figment};
5+
use rocket::{custom, fairing::AdHoc, Build, Orbit, Rocket};
66

77
struct AsyncDropInAsync;
88

@@ -18,8 +18,13 @@ impl Drop for AsyncDropInAsync {
1818

1919
fn rocket() -> Rocket<Build> {
2020
let mut config = rocket::Config::default();
21-
config.secret_key = SecretKey::generate().unwrap();
22-
let figment = Figment::from(config);
21+
#[cfg(feature = "secrets")]
22+
{ config.secret_key = rocket::config::SecretKey::generate().unwrap(); }
23+
let figment = Figment::from(config).merge(Toml::string(r#"
24+
[default]
25+
address = "tcp:127.0.0.1:0"
26+
port = 0
27+
"#).nested());
2328
custom(figment).manage(AsyncDropInAsync).attach(AdHoc::on_liftoff(
2429
"Shutdown immediately",
2530
|rocket: &Rocket<Orbit>| {
@@ -42,12 +47,10 @@ mod launch {
4247
}
4348

4449
mod main {
45-
use rocket::tokio::net::TcpListener;
46-
4750
#[rocket::main]
4851
async fn main() {
4952
super::rocket()
50-
.try_launch_on(TcpListener::bind("localhost:8001"))
53+
.launch()
5154
.await
5255
.unwrap();
5356
}
@@ -59,7 +62,7 @@ mod main {
5962
fn test_execute() {
6063
rocket::execute(async {
6164
super::rocket()
62-
.try_launch_on(TcpListener::bind("localhost:8002"))
65+
.launch()
6366
.await
6467
.unwrap();
6568
});

0 commit comments

Comments
 (0)