-
Notifications
You must be signed in to change notification settings - Fork 265
A test for weird long connection behavior from same Node IDs #3350
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
Draft
RingOfStorms
wants to merge
2
commits into
n0-computer:main
Choose a base branch
from
RingOfStorms:wip_weird_test_cases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -3039,8 +3039,11 @@ mod tests { | |
let (mut send, mut recv) = conn.open_bi().await.e()?; | ||
send.write_all(b"Hello, world!").await.e()?; | ||
send.finish().e()?; | ||
recv.read_to_end(1_000).await.e()?; | ||
let response = recv.read_to_end(1_000).await.e()?; | ||
assert_eq!(&response, b"Hello, world!"); | ||
conn.close(42u32.into(), b"thanks, bye!"); | ||
// TODO this causes a warn that things are not cleaned up gracefully, how can we fail a | ||
// test due to that? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As said on the example: this is about some internal cleanup, nothing that misbehaves for users. You can track this in a separate test that checks there are no warnings logged for a normal connection close. |
||
client.close().await; | ||
|
||
let close_err = server_task.await.e()??; | ||
|
@@ -3054,6 +3057,83 @@ mod tests { | |
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
#[traced_test] | ||
async fn connecting_is_fast_from_same_id_consecutively() -> Result { | ||
const ECHOS: usize = 10; | ||
|
||
let server = Endpoint::builder() | ||
.alpns(vec![TEST_ALPN.to_vec()]) | ||
.relay_mode(RelayMode::Disabled) | ||
.bind() | ||
.await?; | ||
let server_addr = server.node_addr().initialized().await?; | ||
let server_task = tokio::spawn(async move { | ||
let mut close_reasons = Vec::new(); | ||
|
||
for _ in 0..ECHOS { | ||
let incoming = server.accept().await.e()?; | ||
let conn = incoming.await.e()?; | ||
let (mut send, mut recv) = conn.accept_bi().await.e()?; | ||
let msg = recv.read_to_end(1000).await.e()?; | ||
send.write_all(&msg).await.e()?; | ||
send.finish().e()?; | ||
let close_reason = conn.closed().await; | ||
close_reasons.push(close_reason); | ||
} | ||
Ok::<_, Error>(close_reasons) | ||
}); | ||
|
||
let mut elapsed_times = Vec::with_capacity(ECHOS); | ||
for i in 0..ECHOS { | ||
let timer = std::time::Instant::now(); | ||
let client_secret_key = SecretKey::from_bytes(&[0u8; 32]); | ||
let client = Endpoint::builder() | ||
.secret_key(client_secret_key) | ||
// NOTE this is not necessary to trigger the failure so I have it commented out for | ||
// now | ||
// .relay_mode(RelayMode::Disabled) | ||
.bind() | ||
.await?; | ||
let conn = client.connect(server_addr.clone(), TEST_ALPN).await?; | ||
let (mut send, mut recv) = conn.open_bi().await.e()?; | ||
let bytes = format!("Hello, world {i}").into_bytes(); | ||
send.write_all(&bytes).await.e()?; | ||
send.finish().e()?; | ||
let response = recv.read_to_end(1_000).await.e()?; | ||
assert_eq!(&response, &bytes); | ||
conn.close(42u32.into(), b"thanks, bye!"); | ||
client.close().await; | ||
let elapsed = timer.elapsed(); | ||
elapsed_times.push(elapsed); | ||
} | ||
|
||
let close_errs = server_task.await.e()??; | ||
assert_eq!(close_errs.len(), ECHOS); | ||
|
||
for (i, err) in close_errs.into_iter().enumerate() { | ||
let ConnectionError::ApplicationClosed(app_close) = err else { | ||
panic!("Unexpected close reason for conn {i}: {err:?}"); | ||
}; | ||
assert_eq!(app_close.error_code, 42u32.into()); | ||
assert_eq!(app_close.reason.as_ref(), b"thanks, bye!" as &[u8]); | ||
} | ||
|
||
elapsed_times.iter().enumerate().for_each(|(i, elapsed)| { | ||
println!("Elapsed time for connection {i}: {elapsed:?}"); | ||
}); | ||
|
||
// If any of the elapsed times are greater than 3x the minimum throw an error | ||
let min_elapsed = elapsed_times.iter().min().unwrap_or(&Duration::ZERO); | ||
for (i, elapsed) in elapsed_times.iter().enumerate() { | ||
if *elapsed > *min_elapsed * 3 { | ||
panic!("Connection {i} took too long compared to baseline ({min_elapsed:?}): {elapsed:?}"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(feature = "metrics")] | ||
#[tokio::test] | ||
#[traced_test] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove things here again? This is an example, not a debugging tool.
The warning can be checked for in a test. It is about some internal cleanup, nothing on the application layer is misbehaving.