Skip to content

Commit 28254b8

Browse files
committed
Only initialize an outgoing client if the test is in capture mode
There is no reason to initialize this client when in playback mode.
1 parent fe93f2c commit 28254b8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/tests/record.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ pub fn proxy() -> (String, Bomb) {
105105
let handle = core.handle();
106106
let addr = t!(a.local_addr());
107107
let listener = t!(TcpListener::from_listener(a, &addr, &handle));
108-
let client = hyper::Client::builder().build(hyper_tls::HttpsConnector::new(4).unwrap());
108+
let client = if let Record::Capture(_, _) = record {
109+
Some(hyper::Client::builder().build(hyper_tls::HttpsConnector::new(4).unwrap()))
110+
} else {
111+
None
112+
};
109113

110114
let record = Arc::new(Mutex::new(record));
111115
let srv = hyper::Server::builder(listener.incoming().map(|(l, _)| l))
@@ -142,7 +146,7 @@ pub fn proxy() -> (String, Bomb) {
142146
struct Proxy {
143147
sink: Sink,
144148
record: Arc<Mutex<Record>>,
145-
client: Client,
149+
client: Option<Client>,
146150
}
147151

148152
impl hyper::service::Service for Proxy {
@@ -155,7 +159,7 @@ impl hyper::service::Service for Proxy {
155159
fn call(&mut self, req: hyper::Request<Self::ReqBody>) -> Self::Future {
156160
let record2 = self.record.clone();
157161
match *self.record.lock().unwrap() {
158-
Record::Capture(_, _) => Box::new(record_http(req, &self.client).map(
162+
Record::Capture(_, _) => Box::new(record_http(req, self.client.as_ref().unwrap()).map(
159163
move |(response, exchange)| {
160164
if let Record::Capture(ref mut d, _) = *record2.lock().unwrap() {
161165
d.push(exchange);

0 commit comments

Comments
 (0)