Skip to content
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

add test_client_auto_close_when_server_crash test case #104

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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