One less listen address race (#5718)

* One less listen address race
This commit is contained in:
Michael Sproul
2024-05-06 11:59:47 +10:00
committed by GitHub
parent 1af3f0f9d8
commit fe20ef955b
2 changed files with 15 additions and 11 deletions

View File

@@ -14,7 +14,6 @@ use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use std::collections::HashMap;
use std::env;
use std::net::SocketAddr;
use std::time::Duration;
use testcontainers::{clients::Cli, core::WaitFor, Image, RunnableImage};
use tokio::{runtime, task::JoinHandle};
@@ -154,7 +153,7 @@ impl TesterBuilder {
* Create a watch configuration
*/
let database_port = unused_tcp4_port().expect("Unable to find unused port.");
let server_port = unused_tcp4_port().expect("Unable to find unused port.");
let server_port = 0;
let config = Config {
database: DatabaseConfig {
dbname: random_dbname(),
@@ -187,14 +186,9 @@ impl TesterBuilder {
/*
* Spawn a Watch HTTP API.
*/
let watch_server = start_server(&self.config, SLOTS_PER_EPOCH, pool).unwrap();
let (addr, watch_server) = start_server(&self.config, SLOTS_PER_EPOCH, pool).unwrap();
tokio::spawn(watch_server);
let addr = SocketAddr::new(
self.config.server.listen_addr,
self.config.server.listen_port,
);
/*
* Create a HTTP client to talk to the watch HTTP API.
*/