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 1d46855
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 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,12 @@ 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"
"#));
custom(figment).manage(AsyncDropInAsync).attach(AdHoc::on_liftoff(
"Shutdown immediately",
|rocket: &Rocket<Orbit>| {
Expand All @@ -42,12 +46,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 +61,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 1d46855

Please sign in to comment.