Clean up 'on_launch_fairing_can_inspect_port' test.

This commit is contained in:
Sergio Benitez 2021-01-13 17:20:26 -08:00
parent 48fd83a31d
commit 407e346a6a
1 changed files with 7 additions and 15 deletions

View File

@ -1,23 +1,15 @@
#[macro_use]
extern crate rocket;
use rocket::config::Config;
use rocket::fairing::AdHoc;
use rocket::figment::Figment;
use rocket::futures::channel::oneshot;
#[rocket::async_test]
async fn on_launch_fairing_can_inspect_port() {
let (tx, rx) = oneshot::channel();
let mut config = Config::default();
config.port = 0;
tokio::spawn(
rocket::custom(Figment::from(config))
.mount("/", routes![])
.attach(AdHoc::on_launch("Get assigned port", move |rocket| {
tx.send(rocket.config().port).unwrap();
}))
.launch(),
);
assert!(rx.await.unwrap() != 0);
let rocket = rocket::custom(Config { port: 0, ..Default::default() })
.attach(AdHoc::on_launch("Send Port -> Channel", move |rocket| {
tx.send(rocket.config().port).unwrap();
}));
rocket::tokio::spawn(rocket.launch());
assert_ne!(rx.await.unwrap(), 0);
}