Skip to content

Commit 162ff8f

Browse files
authored
Wait for proxy thread to terminate in integration tests (#625)
Signed-off-by: Raphael Taylor-Davies <r.taylordavies@googlemail.com>
1 parent 8a085d5 commit 162ff8f

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

linkerd/app/integration/src/proxy.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub struct Listening {
4141
controller: controller::Listening,
4242
identity: Option<controller::Listening>,
4343

44-
_shutdown: Shutdown,
44+
shutdown: Shutdown,
45+
terminated: oneshot::Receiver<()>,
4546

4647
thread: thread::JoinHandle<()>,
4748
}
@@ -162,9 +163,19 @@ impl Listening {
162163
controller,
163164
identity,
164165
thread,
166+
shutdown,
167+
terminated,
165168
..
166169
} = self;
167-
drop(thread);
170+
171+
debug!("signaling shutdown");
172+
shutdown.signal();
173+
174+
debug!("waiting for proxy termination");
175+
terminated.await.unwrap();
176+
177+
debug!("proxy terminated");
178+
thread.join().unwrap();
168179

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

294305
let (running_tx, running_rx) = oneshot::channel();
306+
let (term_tx, term_rx) = oneshot::channel();
295307
let (tx, mut rx) = shutdown_signal();
296308

297309
if let Some(fut) = proxy.shutdown_signal {
@@ -342,9 +354,12 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
342354
let drain = main.spawn();
343355
on_shutdown.await;
344356
debug!("after on_shutdown");
357+
345358
drain.drain().await;
359+
debug!("after drain");
346360

347-
debug!("after on_shutdown");
361+
// Suppress error as not all tests wait for graceful shutdown
362+
let _ = term_tx.send(());
348363
});
349364
})
350365
})
@@ -386,7 +401,8 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
386401
controller,
387402
identity,
388403

389-
_shutdown: tx,
404+
shutdown: tx,
405+
terminated: term_rx,
390406
thread,
391407
}
392408
}

linkerd/app/integration/tests/transparency.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ async fn outbound_tcp() {
6969

7070
tcp_client.write(msg1).await;
7171
assert_eq!(tcp_client.read().await, msg2.as_bytes());
72+
73+
// TCP client must close first
74+
tcp_client.shutdown().await;
75+
7276
// ensure panics from the server are propagated
7377
proxy.join_servers().await;
7478
}
@@ -95,6 +99,10 @@ async fn inbound_tcp() {
9599

96100
tcp_client.write(msg1).await;
97101
assert_eq!(tcp_client.read().await, msg2.as_bytes());
102+
103+
// TCP client must close first
104+
tcp_client.shutdown().await;
105+
98106
// ensure panics from the server are propagated
99107
proxy.join_servers().await;
100108
}
@@ -181,6 +189,10 @@ async fn test_server_speaks_first(env: TestEnv) {
181189
assert_eq!(s(&tcp_client.read_timeout(TIMEOUT).await), msg1);
182190
tcp_client.write(msg2).await;
183191
timeout(TIMEOUT, rx.recv()).await.unwrap();
192+
193+
// TCP client must close first
194+
tcp_client.shutdown().await;
195+
184196
// ensure panics from the server are propagated
185197
proxy.join_servers().await;
186198
}
@@ -491,6 +503,9 @@ macro_rules! http1_tests {
491503
let chat_resp = tcp_client.read().await;
492504
assert_eq!(s(&chat_resp), chatproto_res);
493505

506+
// TCP client must close first
507+
tcp_client.shutdown().await;
508+
494509
// ensure panics from the server are propagated
495510
proxy.join_servers().await;
496511
}
@@ -640,6 +655,9 @@ macro_rules! http1_tests {
640655
let resp2 = tcp_client.read().await;
641656
assert_eq!(s(&resp2), s(&tunneled_res[..]));
642657

658+
// TCP client must close first
659+
tcp_client.shutdown().await;
660+
643661
// ensure panics from the server are propagated
644662
proxy.join_servers().await;
645663
}

linkerd/app/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl App {
291291
..
292292
} = self;
293293

294-
// Run a daemon thread for all administative tasks.
294+
// Run a daemon thread for all administrative tasks.
295295
//
296296
// The main reactor holds `admin_shutdown_tx` until the reactor drops
297297
// the task. This causes the daemon reactor to stop.

0 commit comments

Comments
 (0)