Skip to content

Commit

Permalink
MAIN: Add test for connect timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
naterichman committed Nov 7, 2024
1 parent bf171c0 commit b889ea1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
43 changes: 43 additions & 0 deletions ul/tests/association.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use dicom_dictionary_std::uids::VERIFICATION;
use dicom_ul::ClientAssociationOptions;
use rstest::rstest;
use std::time::Instant;

#[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 + 10).into());
}

#[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 + 10).into());
}

0 comments on commit b889ea1

Please sign in to comment.