Skip to content

Commit ae3b36c

Browse files
authored
fix(bindings/bench): Prevent IO from going out of scope (#5007)
1 parent a5d4e67 commit ae3b36c

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

.github/workflows/bench.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Benchmarking
22

33
on:
4+
pull_request:
5+
branches: [main]
46
push:
57
branches: [main]
68
schedule:
@@ -29,23 +31,25 @@ jobs:
2931
pip3 install "boto3[crt]"
3032
3133
- name: Generate
32-
working-directory: bindings/rust
34+
working-directory: bindings/rust/extended
3335
run: ./generate.sh --skip-tests
3436

3537
- name: Benchmark
36-
working-directory: bindings/rust/bench
38+
working-directory: bindings/rust/standard/bench
3739
run: cargo criterion --message-format json > criterion_output.log
3840

3941
- name: Configure AWS Credentials
42+
if: github.event_name == 'push'
4043
uses: aws-actions/[email protected]
4144
with:
4245
role-to-assume: arn:aws:iam::024603541914:role/GitHubOIDCRole
4346
role-session-name: s2ntlsghabenchsession
4447
aws-region: us-west-2
4548

4649
- name: Emit CloudWatch metrics
50+
if: github.event_name == 'push'
4751
run: |
4852
python3 .github/bin/criterion_to_cloudwatch.py \
49-
--criterion_output_path bindings/rust/bench/criterion_output.log \
53+
--criterion_output_path bindings/rust/standard/bench/criterion_output.log \
5054
--namespace s2n-tls-bench \
5155
--platform ${{ runner.os }}-${{ runner.arch }}

bindings/rust/standard/bench/benches/resumption.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,18 @@ where
4545
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| {
4646
b.iter_batched_ref(
4747
|| {
48-
let pair = TlsConnPair::<T, T>::new_bench_pair(
48+
let mut pair = TlsConnPair::<T, T>::new_bench_pair(
4949
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type),
5050
handshake,
5151
)
5252
.unwrap();
53-
let (mut c, s) = pair.split();
54-
c.handshake().unwrap();
55-
s
53+
pair.client_mut().handshake().unwrap();
54+
pair
5655
},
57-
|server| {
56+
|pair| {
5857
// this represents the work that the server does during the
5958
// first RTT
60-
server.handshake().unwrap()
59+
pair.server_mut().handshake().unwrap();
6160
},
6261
BatchSize::SmallInput,
6362
)

bindings/rust/standard/bench/src/harness/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,20 @@ where
260260
Self { client, server, io }
261261
}
262262

263-
/// Take back ownership of individual connections in the TlsConnPair
264-
pub fn split(self) -> (C, S) {
265-
(self.client, self.server)
263+
pub fn client(&self) -> &C {
264+
&self.client
265+
}
266+
267+
pub fn client_mut(&mut self) -> &mut C {
268+
&mut self.client
269+
}
270+
271+
pub fn server(&self) -> &S {
272+
&self.server
273+
}
274+
275+
pub fn server_mut(&mut self) -> &mut S {
276+
&mut self.server
266277
}
267278

268279
/// Run handshake on connections
@@ -386,8 +397,7 @@ mod tests {
386397
TlsConnPair::<C, S>::new_bench_pair(CryptoConfig::default(), HandshakeType::Resumption)
387398
.unwrap();
388399
conn_pair.handshake().unwrap();
389-
let (_, server) = conn_pair.split();
390-
assert!(server.resumed_connection());
400+
assert!(conn_pair.server().resumed_connection());
391401
}
392402

393403
#[test]

0 commit comments

Comments
 (0)