Skip to content

Commit

Permalink
Update tests to use unnumbered ports
Browse files Browse the repository at this point in the history
  • Loading branch information
the10thWiz committed Aug 10, 2024
1 parent 7b1a40b commit 8742c65
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/lib/tests/drop-in-async-context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[macro_use]
extern crate rocket;

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

struct AsyncDropInAsync;

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

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

mod main {
use rocket::tokio::net::TcpListener;

#[rocket::main]
async fn main() {
super::rocket()
.try_launch_on(TcpListener::bind("localhost:8001"))
.launch()
.await
.unwrap();
}
Expand All @@ -59,7 +62,7 @@ mod main {
fn test_execute() {
rocket::execute(async {
super::rocket()
.try_launch_on(TcpListener::bind("localhost:8002"))
.launch()
.await
.unwrap();
});
Expand Down

0 comments on commit 8742c65

Please sign in to comment.