mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-24 04:57:00 +01:00
Add port verification to start server in kanidm_client tests
Ports could be already allocated and tests start failing depending on the execution environment.
This commit is contained in:
parent
c554a0ce03
commit
ec754ece37
|
@ -1,4 +1,5 @@
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::net::TcpStream;
|
||||||
|
use std::sync::atomic::{AtomicU16, Ordering};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use kanidm::audit::LogLevel;
|
use kanidm::audit::LogLevel;
|
||||||
|
@ -10,7 +11,14 @@ use async_std::task;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
pub const ADMIN_TEST_PASSWORD: &str = "integration test admin password";
|
pub const ADMIN_TEST_PASSWORD: &str = "integration test admin password";
|
||||||
static PORT_ALLOC: AtomicUsize = AtomicUsize::new(8080);
|
static PORT_ALLOC: AtomicU16 = AtomicU16::new(8080);
|
||||||
|
|
||||||
|
fn is_free_port(port: u16) -> bool {
|
||||||
|
match TcpStream::connect(("0.0.0.0", port)) {
|
||||||
|
Ok(_) => false,
|
||||||
|
Err(_) => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test external behaviours of the service.
|
// Test external behaviours of the service.
|
||||||
|
|
||||||
|
@ -25,7 +33,12 @@ pub fn run_test(test_fn: fn(KanidmClient) -> ()) {
|
||||||
let (mut ready_tx, mut ready_rx) = mpsc::channel(1);
|
let (mut ready_tx, mut ready_rx) = mpsc::channel(1);
|
||||||
let (mut finish_tx, mut finish_rx) = mpsc::channel(1);
|
let (mut finish_tx, mut finish_rx) = mpsc::channel(1);
|
||||||
|
|
||||||
let port = PORT_ALLOC.fetch_add(1, Ordering::SeqCst);
|
let port = loop {
|
||||||
|
let possible_port = PORT_ALLOC.fetch_add(1, Ordering::SeqCst);
|
||||||
|
if is_free_port(possible_port) {
|
||||||
|
break possible_port;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let int_config = Box::new(IntegrationTestConfig {
|
let int_config = Box::new(IntegrationTestConfig {
|
||||||
admin_password: ADMIN_TEST_PASSWORD.to_string(),
|
admin_password: ADMIN_TEST_PASSWORD.to_string(),
|
||||||
|
|
Loading…
Reference in a new issue