Skip to content

Commit c8e6234

Browse files
Techassisbernauer
andauthored
test: Improve stackable-certs test speeds (#763)
* test: Improve stackable-certs test speeds This commit increases the optimization level for the stackable-certs crate during test runs to O2 to speed up the RSA key generation. Additionally, it only uses 2048 bit long keys instead of 4096 used in release builds. Further, it also disables two doc tests. * Further reduce test times down to < 0.5s * fixup comment * test: Add test-case for ecdsa --------- Co-authored-by: Sebastian Bernauer <[email protected]>
1 parent 51e7e1c commit c8e6234

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
6666
url = "2.5.0"
6767
x509-cert = { version = "0.2.5", features = ["builder"] }
6868
zeroize = "1.7.0"
69+
70+
# Use O3 in tests to improve the RSA key generation speed in the stackable-certs crate
71+
[profile.test.package.stackable-certs]
72+
opt-level = 3
73+
[profile.test.package."rsa"]
74+
opt-level = 3

crates/stackable-certs/src/ca/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,16 @@ mod test {
477477
use super::*;
478478

479479
#[tokio::test]
480-
async fn test() {
480+
async fn test_rsa_key_generation() {
481481
let mut ca = CertificateAuthority::new_rsa().unwrap();
482-
ca.generate_leaf_certificate(
483-
rsa::SigningKey::new().unwrap(),
484-
"Airflow",
485-
"pod",
486-
Duration::from_secs(3600),
487-
)
488-
.unwrap();
482+
ca.generate_rsa_leaf_certificate("Airflow", "pod", Duration::from_secs(3600))
483+
.unwrap();
484+
}
485+
486+
#[tokio::test]
487+
async fn test_ecdsa_key_generation() {
488+
let mut ca = CertificateAuthority::new_ecdsa().unwrap();
489+
ca.generate_ecdsa_leaf_certificate("Airflow", "pod", Duration::from_secs(3600))
490+
.unwrap();
489491
}
490492
}

crates/stackable-certs/src/keys/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! [`ecdsa`], which provides primitives and traits, and [`p256`] which
1010
//! implements the NIST P-256 elliptic curve and supports ECDSA.
1111
//!
12-
//! ```
12+
//! ```ignore
1313
//! use stackable_certs::keys::ecdsa::SigningKey;
1414
//! let key = SigningKey::new().unwrap();
1515
//! ```
@@ -18,7 +18,7 @@
1818
//!
1919
//! In order to work with RSA keys, this crate requires the [`rsa`] dependency.
2020
//!
21-
//! ```
21+
//! ```ignore
2222
//! use stackable_certs::keys::rsa::SigningKey;
2323
//! let key = SigningKey::new().unwrap();
2424
//! ```

crates/stackable-certs/src/keys/rsa.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ use tracing::instrument;
99

1010
use crate::keys::CertificateKeypair;
1111

12+
#[cfg(not(test))]
1213
const KEY_SIZE: usize = 4096;
1314

15+
#[cfg(test)]
16+
const KEY_SIZE: usize = 512;
17+
1418
pub type Result<T, E = Error> = std::result::Result<T, E>;
1519

1620
#[derive(Debug, PartialEq, Snafu)]

0 commit comments

Comments
 (0)