Files
nuchat/tests/common/mod.rs
Fergus Molloy 9a2caf0921
Some checks failed
Cargo / build (push) Failing after 2m55s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 8s
spawn app for each integration test
also adds missing dep to flake
2025-07-18 09:04:37 +01:00

17 lines
633 B
Rust

use std::net::TcpListener;
pub fn spawn_app() -> String {
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
let _ = listener.set_nonblocking(true);
// We retrieve the port assigned to us by the OS
let port = listener.local_addr().unwrap().port();
let server = nuchat::run(
tokio::net::TcpListener::from_std(listener)
.expect("Failed to convert from_std to tokio listener"),
)
.expect("Failed to bind address");
tokio::spawn(server.into_future());
// We return the application address to the caller!
format!("http://127.0.0.1:{port}")
}