-
Notifications
You must be signed in to change notification settings - Fork 17
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
Showing
3 changed files
with
45 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "stubborn-io" | ||
version = "0.3.2" | ||
version = "0.3.3" | ||
authors = ["David Raifaizen <[email protected]>"] | ||
edition = "2021" | ||
description = "io traits/structs that automatically recover from potential disconnections/interruptions." | ||
|
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); | ||
} |