Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAIN: Add test for connect timeout #596

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions ul/tests/association.rs
Original file line number Diff line number Diff line change
@@ -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("[email protected]: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("[email protected]: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
);
}
Loading