Skip to content

Commit 3541f76

Browse files
authored
test: reduce repetition in metrics tests (#860)
Currently, the metrics tests have a bunch of code that's repeated between tests in the inbound and outbound directions. This makes modifying the tests much more painful, since the code needs to be changed multiple times. Also, the file is hard to navigate. This commit changes this by factoring out the shared code into functions which are called by the differing code (e.g. metrics labels) as parameters. This means that the common behavior is only defined once, so it should be somewhat easier to edit. This has a significant advantage over the approach we use elsewhere, where similar tests are generated by macros: it doesn't mess up the compiler diagnostics for errors in the tests. We may want to refactor other tests to use a similar style in the future. Signed-off-by: Eliza Weisman <[email protected]>
1 parent 1e98a5b commit 3541f76

File tree

2 files changed

+502
-558
lines changed

2 files changed

+502
-558
lines changed

linkerd/app/integration/src/client.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub fn tcp(addr: SocketAddr) -> tcp::TcpClient {
8383
tcp::client(addr)
8484
}
8585
pub struct Client {
86+
addr: SocketAddr,
87+
run: Run,
8688
authority: String,
8789
/// This is a future that completes when the associated connection for
8890
/// this Client has been dropped.
@@ -93,6 +95,13 @@ pub struct Client {
9395
tls: Option<TlsConfig>,
9496
}
9597

98+
pub struct Reconnect {
99+
addr: SocketAddr,
100+
authority: String,
101+
run: Run,
102+
tls: Option<TlsConfig>,
103+
}
104+
96105
impl Client {
97106
fn new(addr: SocketAddr, authority: String, r: Run, tls: Option<TlsConfig>) -> Client {
98107
let v = match r {
@@ -101,6 +110,8 @@ impl Client {
101110
};
102111
let (tx, task, running) = run(addr, r, tls.clone());
103112
Client {
113+
addr,
114+
run: r,
104115
authority,
105116
running,
106117
task,
@@ -172,18 +183,39 @@ impl Client {
172183
self.running.await
173184
}
174185

175-
pub async fn shutdown(self) {
186+
/// Shut down the client, returning a type that can be used to initiate a
187+
/// new client connection to that target.
188+
pub async fn shutdown(self) -> Reconnect {
176189
let Self {
177-
tx, task, running, ..
190+
tx,
191+
task,
192+
running,
193+
run,
194+
addr,
195+
authority,
196+
tls,
197+
..
178198
} = self;
179199
// signal the client task to shut down now.
180200
drop(tx);
181201
task.await.unwrap();
182202
running.await;
203+
Reconnect {
204+
authority,
205+
run,
206+
addr,
207+
tls,
208+
}
209+
}
210+
}
211+
212+
impl Reconnect {
213+
pub fn reconnect(self) -> Client {
214+
Client::new(self.addr, self.authority, self.run, self.tls)
183215
}
184216
}
185217

186-
#[derive(Debug)]
218+
#[derive(Debug, Clone, Copy)]
187219
enum Run {
188220
Http1 { absolute_uris: bool },
189221
Http2,

0 commit comments

Comments
 (0)