Skip to content

Commit

Permalink
style: simplfy api for test utility (#4008)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmayclin authored May 16, 2023
1 parent 8584b89 commit f9a6ffa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
3 changes: 1 addition & 2 deletions bindings/rust/s2n-tls/src/callbacks/pkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ mod tests {
use futures_test::task::new_count_waker;
use openssl::{ec::EcKey, ecdsa::EcdsaSig};

const MAX_POLLS: usize = 100;
type Error = Box<dyn std::error::Error>;

const KEY: &[u8] = include_bytes!(concat!(
Expand Down Expand Up @@ -171,7 +170,7 @@ mod tests {
Harness::new(client)
};

Ok(Pair::new(server, client, MAX_POLLS))
Ok(Pair::new(server, client))
}

fn ecdsa_sign(
Expand Down
18 changes: 9 additions & 9 deletions bindings/rust/s2n-tls/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ pub mod s2n_tls;
type Error = Box<dyn std::error::Error>;
type Result<T, E = Error> = core::result::Result<T, E>;

/// The number of iterations that will be executed until the handshake exits with an error
///
/// This is to prevent endless looping without making progress on the connection.
const SAMPLES: usize = 100;

pub fn test_error(msg: &str) -> crate::error::Error {
crate::error::Error::application(msg.into())
}
Expand Down Expand Up @@ -74,11 +69,16 @@ pub struct Pair<Server: Connection, Client: Connection> {
}

impl<Server: Connection, Client: Connection> Pair<Server, Client> {
pub fn new(server: Server, client: Client, max_iterations: usize) -> Self {
/// The number of iterations that will be executed until the handshake exits with an error
///
/// This is to prevent endless looping without making progress on the connection.
const DEFAULT_ITERATIONS: usize = 100;

pub fn new(server: Server, client: Client) -> Self {
Self {
server: (server, Default::default()),
client: (client, Default::default()),
max_iterations,
max_iterations: Self::DEFAULT_ITERATIONS,
}
}
pub fn poll(&mut self) -> Poll<Result<()>> {
Expand Down Expand Up @@ -239,7 +239,7 @@ pub fn tls_pair(config: crate::config::Config) -> Pair<Harness, Harness> {
.expect("Unable to set client config");
let client = Harness::new(client);

Pair::new(server, client, SAMPLES)
Pair::new(server, client)
}

pub fn establish_connection(config: crate::config::Config) {
Expand All @@ -257,7 +257,7 @@ pub fn establish_connection(config: crate::config::Config) {
.expect("Unable to set client config");
let client = Harness::new(client);

let pair = Pair::new(server, client, SAMPLES);
let pair = Pair::new(server, client);
poll_tls_pair(pair);
}

Expand Down
12 changes: 6 additions & 6 deletions bindings/rust/s2n-tls/src/testing/s2n_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ mod tests {
Harness::new(client)
};

let mut pair = Pair::new(server, client, SAMPLES);
let mut pair = Pair::new(server, client);
loop {
match pair.poll() {
Poll::Ready(result) => {
Expand Down Expand Up @@ -373,7 +373,7 @@ mod tests {
Harness::new(client)
};

let mut pair = Pair::new(server, client, SAMPLES);
let mut pair = Pair::new(server, client);
loop {
match pair.poll() {
Poll::Ready(result) => {
Expand Down Expand Up @@ -427,7 +427,7 @@ mod tests {
Harness::new(client)
};

let pair = Pair::new(server, client, SAMPLES);
let pair = Pair::new(server, client);

poll_tls_pair(pair);
// confirm that the callback returned Pending `require_pending_count` times
Expand Down Expand Up @@ -496,7 +496,7 @@ mod tests {
Harness::new(client)
};

let pair = Pair::new(server, client, SAMPLES);
let pair = Pair::new(server, client);

assert_eq!(callback.count(), 0);
poll_tls_pair(pair);
Expand Down Expand Up @@ -590,7 +590,7 @@ mod tests {
Harness::new(client)
};

let pair = Pair::new(server, client, SAMPLES);
let pair = Pair::new(server, client);
let pair = poll_tls_pair(pair);
let server = pair.server.0.connection;
let client = pair.client.0.connection;
Expand Down Expand Up @@ -630,7 +630,7 @@ mod tests {
Harness::new(client)
};

let pair = Pair::new(server, client, SAMPLES);
let pair = Pair::new(server, client);
let pair = poll_tls_pair(pair);
let server = pair.server.0.connection;
let client = pair.client.0.connection;
Expand Down

0 comments on commit f9a6ffa

Please sign in to comment.