fix tests spinning up server
Some checks failed
Cargo / check (push) Successful in 28s
Cargo / build (push) Successful in 34s
Cargo / test (push) Failing after 37s

This commit is contained in:
2025-07-18 15:10:54 +01:00
parent 8a2b1d504a
commit 2fff50ec0a
6 changed files with 67 additions and 30 deletions

View File

@ -1,16 +0,0 @@
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}")
}