Skip to content

Wait for proxy thread to terminate in integration tests #625

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

Merged
merged 1 commit into from
Aug 18, 2020
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
24 changes: 20 additions & 4 deletions linkerd/app/integration/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub struct Listening {
controller: controller::Listening,
identity: Option<controller::Listening>,

_shutdown: Shutdown,
shutdown: Shutdown,
terminated: oneshot::Receiver<()>,

thread: thread::JoinHandle<()>,
}
Expand Down Expand Up @@ -162,9 +163,19 @@ impl Listening {
controller,
identity,
thread,
shutdown,
terminated,
..
} = self;
drop(thread);

debug!("signaling shutdown");
shutdown.signal();

debug!("waiting for proxy termination");
terminated.await.unwrap();

debug!("proxy terminated");
thread.join().unwrap();

let outbound = async move {
if let Some(srv) = outbound_server {
Expand Down Expand Up @@ -292,6 +303,7 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
let (trace, trace_handle) = super::trace_subscriber();

let (running_tx, running_rx) = oneshot::channel();
let (term_tx, term_rx) = oneshot::channel();
let (tx, mut rx) = shutdown_signal();

if let Some(fut) = proxy.shutdown_signal {
Expand Down Expand Up @@ -339,9 +351,12 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
let drain = main.spawn();
on_shutdown.await;
debug!("after on_shutdown");

drain.drain().await;
debug!("after drain");

debug!("after on_shutdown");
// Suppress error as not all tests wait for graceful shutdown
let _ = term_tx.send(());
});
})
})
Expand Down Expand Up @@ -383,7 +398,8 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
controller,
identity,

_shutdown: tx,
shutdown: tx,
terminated: term_rx,
thread,
}
}
18 changes: 18 additions & 0 deletions linkerd/app/integration/tests/transparency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ async fn outbound_tcp() {

tcp_client.write(msg1).await;
assert_eq!(tcp_client.read().await, msg2.as_bytes());

// TCP client must close first
tcp_client.shutdown().await;

// ensure panics from the server are propagated
proxy.join_servers().await;
}
Expand All @@ -95,6 +99,10 @@ async fn inbound_tcp() {

tcp_client.write(msg1).await;
assert_eq!(tcp_client.read().await, msg2.as_bytes());

// TCP client must close first
tcp_client.shutdown().await;

// ensure panics from the server are propagated
proxy.join_servers().await;
}
Expand Down Expand Up @@ -181,6 +189,10 @@ async fn test_server_speaks_first(env: TestEnv) {
assert_eq!(s(&tcp_client.read_timeout(TIMEOUT).await), msg1);
tcp_client.write(msg2).await;
timeout(TIMEOUT, rx.recv()).await.unwrap();

// TCP client must close first
tcp_client.shutdown().await;

// ensure panics from the server are propagated
proxy.join_servers().await;
}
Expand Down Expand Up @@ -491,6 +503,9 @@ macro_rules! http1_tests {
let chat_resp = tcp_client.read().await;
assert_eq!(s(&chat_resp), chatproto_res);

// TCP client must close first
tcp_client.shutdown().await;

// ensure panics from the server are propagated
proxy.join_servers().await;
}
Expand Down Expand Up @@ -640,6 +655,9 @@ macro_rules! http1_tests {
let resp2 = tcp_client.read().await;
assert_eq!(s(&resp2), s(&tunneled_res[..]));

// TCP client must close first
tcp_client.shutdown().await;

// ensure panics from the server are propagated
proxy.join_servers().await;
}
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl App {
..
} = self;

// Run a daemon thread for all administative tasks.
// Run a daemon thread for all administrative tasks.
//
// The main reactor holds `admin_shutdown_tx` until the reactor drops
// the task. This causes the daemon reactor to stop.
Expand Down