forked from Enet4/dicom-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Enet4#596 from naterichman/connect-timeout-test
MAIN: Add test for connect timeout
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("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 | ||
); | ||
} |