diff --git a/.github/workflows/qc.yaml b/.github/workflows/qc.yaml index 2f9a0db..cd213f7 100644 --- a/.github/workflows/qc.yaml +++ b/.github/workflows/qc.yaml @@ -121,7 +121,7 @@ jobs: # liboqs requires quite a lot of stack memory, thus we adjust # the default stack size picked for new threads (which is used # by `cargo test`) to be _big enough_. Setting it to 8 MiB - - run: RUST_MIN_STACK=8388608 cargo test --workspace + - run: RUST_MIN_STACK=8388608 cargo test --workspace --features integration_test cargo-test-nix-devshell-x86_64-linux: runs-on: diff --git a/rosenpass/src/app_server.rs b/rosenpass/src/app_server.rs index adb862e..317d52f 100644 --- a/rosenpass/src/app_server.rs +++ b/rosenpass/src/app_server.rs @@ -830,6 +830,7 @@ impl AppServer { 0.0 }; + #[cfg(feature = "integration_test")] let prev_under_load = self.under_load; if load_ratio > UNDER_LOAD_RATIO { self.under_load = DoSOperation::UnderLoad; diff --git a/rosenpass/tests/integration_test.rs b/rosenpass/tests/integration_test.rs index 553cda3..634dc51 100644 --- a/rosenpass/tests/integration_test.rs +++ b/rosenpass/tests/integration_test.rs @@ -1,4 +1,4 @@ -use std::{fs, net::UdpSocket, path::PathBuf, process::Stdio, thread::sleep, time::Duration}; +use std::{fs, net::UdpSocket, path::PathBuf, process::Stdio, time::Duration}; const BIN: &str = "rosenpass"; @@ -28,13 +28,13 @@ fn generate_keys() { fs::remove_dir_all(&tmpdir).unwrap(); } -fn find_udp_socket() -> u16 { +fn find_udp_socket() -> Option { for port in 1025..=u16::MAX { if UdpSocket::bind(("127.0.0.1", port)).is_ok() { - return port; + return Some(port); } } - panic!("no free UDP port found"); + None } // check that we can exchange keys @@ -63,7 +63,12 @@ fn check_exchange_under_normal() { } // start first process, the server - let port = find_udp_socket(); + let port = loop { + if let Some(port) = find_udp_socket() { + break port; + } + }; + let listen_addr = format!("localhost:{port}"); let mut server = test_bin::get_test_bin(BIN) .args(["exchange", "secret-key"]) @@ -153,7 +158,11 @@ fn check_exchange_under_dos() { } // start first process, the server - let port = find_udp_socket(); + let port = loop { + if let Some(port) = find_udp_socket() { + break port; + } + }; let listen_addr = format!("localhost:{port}"); let mut server = test_bin::get_test_bin(BIN) .args(["exchange", "secret-key"]) @@ -185,7 +194,7 @@ fn check_exchange_under_dos() { .send_to(&buf, &server_addr) .expect("couldn't send data"); - sleep(Duration::from_micros(10)); + std::thread::sleep(Duration::from_micros(10)); } });