diff --git a/Cargo.lock b/Cargo.lock index ce520360..aa30e13f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -672,9 +672,12 @@ version = "0.8.0" dependencies = [ "byteordered", "bytes", + "dicom-core", + "dicom-dictionary-std", "dicom-encoding", "dicom-transfer-syntax-registry", "matches", + "rstest", "snafu", "tokio", "tracing", diff --git a/ul/Cargo.toml b/ul/Cargo.toml index aac41f79..88fc1a81 100644 --- a/ul/Cargo.toml +++ b/ul/Cargo.toml @@ -31,7 +31,10 @@ features = [ ] [dev-dependencies] +dicom-core = { path = "../core" } +dicom-dictionary-std = { path = "../dictionary-std" } matches = "0.1.8" +rstest = "0.23.0" tokio = { version = "^1.38", features = ["io-util", "macros", "net", "rt", "rt-multi-thread"] } [features] diff --git a/ul/tests/association.rs b/ul/tests/association.rs new file mode 100644 index 00000000..90e7a3c1 --- /dev/null +++ b/ul/tests/association.rs @@ -0,0 +1,55 @@ +use dicom_dictionary_std::uids::VERIFICATION; +use dicom_ul::ClientAssociationOptions; +use rstest::rstest; +use std::time::Instant; + +const TIMEOUT_TOLERANCE: u64 = 25; + +#[rstest] +#[case(100)] +#[case(500)] +#[case(1000)] +fn test_slow_association(#[case] timeout: u64) { + let scu_init = ClientAssociationOptions::new() + .with_abstract_syntax(VERIFICATION) + .calling_ae_title("RANDOM") + .read_timeout(std::time::Duration::from_secs(1)) + .connection_timeout(std::time::Duration::from_millis(timeout)); + + let now = Instant::now(); + let _res = scu_init.establish_with("RANDOM@167.167.167.167:11111"); + let elapsed = now.elapsed(); + assert!( + elapsed.as_millis() < (timeout + TIMEOUT_TOLERANCE).into(), + "Elapsed time {}ms exceeded the timeout {}ms", + elapsed.as_millis(), + timeout + ); +} + +#[cfg(feature = "async")] +#[rstest] +#[case(100)] +#[case(500)] +#[case(1000)] +#[tokio::test(flavor = "multi_thread")] +async fn test_slow_association_async(#[case] timeout: u64) { + let scu_init = ClientAssociationOptions::new() + .with_abstract_syntax(VERIFICATION) + .calling_ae_title("RANDOM") + .read_timeout(std::time::Duration::from_secs(1)) + .connection_timeout(std::time::Duration::from_millis(timeout)); + let now = Instant::now(); + let res = scu_init + .establish_with_async("RANDOM@167.167.167.167:11111") + .await; + assert!(res.is_err()); + let elapsed = now.elapsed(); + println!("Elapsed time: {:?}", elapsed); + assert!( + elapsed.as_millis() < (timeout + TIMEOUT_TOLERANCE).into(), + "Elapsed time {}ms exceeded the timeout {}ms", + elapsed.as_millis(), + timeout + ); +}