forked from craftytrickster/stubborn-io
-
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.
Ensure multiple shutdown attempts behave correctly (#25)
* Ensure multiple shutdown attempts behave correctly --------- Authored-by: Caleb Leinz <[email protected]>
- Loading branch information
1 parent
64f22da
commit d87d511
Showing
2 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
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,28 @@ | ||
use std::time::Duration; | ||
|
||
use stubborn_io::StubbornTcpStream; | ||
use tokio::{io::AsyncWriteExt, sync::oneshot}; | ||
|
||
#[tokio::test] | ||
async fn back_to_back_shutdown_attempts() { | ||
let (port_tx, port_rx) = oneshot::channel(); | ||
tokio::spawn(async move { | ||
let mut streams = Vec::new(); | ||
let listener = tokio::net::TcpListener::bind("0.0.0.0:0").await.unwrap(); | ||
let addr = listener.local_addr().unwrap(); | ||
port_tx.send(addr).unwrap(); | ||
loop { | ||
let (stream, _addr) = listener.accept().await.unwrap(); | ||
streams.push(stream); | ||
} | ||
}); | ||
let addr = port_rx.await.unwrap(); | ||
let mut connection = StubbornTcpStream::connect(addr).await.unwrap(); | ||
|
||
connection.shutdown().await.unwrap(); | ||
let elapsed = tokio::time::timeout(Duration::from_secs(5), connection.shutdown()).await; | ||
|
||
let result = elapsed.unwrap(); | ||
let error = result.unwrap_err(); | ||
assert_eq!(error.kind(), std::io::ErrorKind::NotConnected); | ||
} |