Skip to content

Commit

Permalink
add test_client_auto_close_when_server_crash test case (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
sword-jin authored Aug 9, 2024
1 parent 182c783 commit b0340f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Client {
let dialer = tunnel.dialer;

tokio::spawn(async move {
let _delay = shutdown.delay_shutdown_token();
if let Err(err) = self
.handle_tunnel(
shutdown.wait_shutdown_triggered(),
Expand Down
2 changes: 1 addition & 1 deletion src/server/data_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ mod test {
use async_shutdown::ShutdownManager;
use tokio::time::sleep;

use crate::debug;
// use crate::debug;

use super::*;

Expand Down
32 changes: 32 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,38 @@ async fn test_assigned_entrypoint() {
}
}

#[tokio::test]
async fn test_client_auto_close_when_server_crash() {
init();
let server = start_server(Default::default()).await;
let control_addr = server.control_addr().clone();

let client_handler = tokio::spawn(async move {
sleep(tokio::time::Duration::from_millis(50)).await; // wait for server to start
let shutdown = ShutdownManager::new();

let client = Client::new(control_addr).await.unwrap();
let _ = client
.start_tunnel(
Tunnel::new(
"test",
SocketAddr::from(([127, 0, 0, 1], 8971)),
RemoteConfig::Tcp(free_port().unwrap()),
),
shutdown.clone(),
)
.await;

shutdown.wait_shutdown_complete().await;
});

sleep(tokio::time::Duration::from_millis(200)).await;
server.cancel.trigger_shutdown(0).unwrap();

let client_exit = tokio::join!(client_handler);
assert!(client_exit.0.is_ok());
}

struct TestServer {
control_port: u16,
vhttp_port: u16,
Expand Down

0 comments on commit b0340f6

Please sign in to comment.