From 399862d955ec6552b0ce71bcd7638344972e8dab Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 20 Jun 2022 11:17:59 +0200 Subject: [PATCH] test: Run tests faster with `nextest`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > [`cargo-nextest`](https://nexte.st/index.html) is a next-generation > test runner for Rust projects. This patch installs and uses `nextest` to run our own tests. Comparing `cargo test` and `cargo nextest` with hyperfine provides the following results: ```sh $ hyperfine 'cargo test --workspace' 'cargo nextest run --workspace && cargo test --doc' Benchmark 1: cargo test --workspace Time (mean ± σ): 51.785 s ± 2.066 s [User: 183.471 s, System: 10.563 s] Range (min … max): 49.151 s … 56.641 s 10 runs Benchmark 2: cargo nextest run --workspace && cargo test --doc Time (mean ± σ): 44.556 s ± 0.894 s [User: 192.213 s, System: 11.441 s] Range (min … max): 43.170 s … 45.762 s 10 runs ``` Benchmark 2 is 1.16 times faster than Benchmark 1. --- .github/workflows/appservice.yml | 3 +++ .github/workflows/ci.yml | 9 ++++++++- .github/workflows/wasm.yml | 3 +++ xtask/src/ci.rs | 10 ++++++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/appservice.yml b/.github/workflows/appservice.yml index 42fd7dce107..8c0195146ca 100644 --- a/.github/workflows/appservice.yml +++ b/.github/workflows/appservice.yml @@ -39,6 +39,9 @@ jobs: - name: Load cache uses: Swatinem/rust-cache@v1 + - name: Install nextest + uses: taiki-e/install-action@nextest + - name: Run checks uses: actions-rs/cargo@v1 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10053774f4a..dde1af5379e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,9 @@ jobs: - name: Load cache uses: Swatinem/rust-cache@v1 + - name: Install nextest + uses: taiki-e/install-action@nextest + - name: Test uses: actions-rs/cargo@v1 with: @@ -115,10 +118,14 @@ jobs: - name: Load cache uses: Swatinem/rust-cache@v1 + - name: Install nextest + uses: taiki-e/install-action@nextest + - name: Test uses: actions-rs/cargo@v1 with: - command: test + command: nextest + args: run test-nodejs: name: linux / node.js (${{ matrix.node-version }}) diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 11e29367641..47fa9d1967a 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -62,6 +62,9 @@ jobs: - name: Load cache uses: Swatinem/rust-cache@v1 + - name: Install nextest + uses: taiki-e/install-action@nextest + - name: Rust Check uses: actions-rs/cargo@v1 with: diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index fec35730c0b..e2ec7ff8a8f 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -164,7 +164,9 @@ fn run_feature_tests(cmd: Option) -> Result<()> { ]); let run = |arg_set: &str| { - cmd!("rustup run stable cargo test -p matrix-sdk").args(arg_set.split_whitespace()).run() + cmd!("rustup run stable cargo nextest run -p matrix-sdk") + .args(arg_set.split_whitespace()) + .run() }; match cmd { @@ -186,15 +188,15 @@ fn run_crypto_tests() -> Result<()> { "rustup run stable cargo clippy -p matrix-sdk-crypto --features=backups_v1 -- -D warnings" ) .run()?; - cmd!("rustup run stable cargo test -p matrix-sdk-crypto --features=backups_v1").run()?; - cmd!("rustup run stable cargo test -p matrix-sdk-crypto-ffi").run()?; + cmd!("rustup run stable cargo nextest run -p matrix-sdk-crypto --features=backups_v1").run()?; + cmd!("rustup run stable cargo nextest run -p matrix-sdk-crypto-ffi").run()?; Ok(()) } fn run_appservice_tests() -> Result<()> { cmd!("rustup run stable cargo clippy -p matrix-sdk-appservice -- -D warnings").run()?; - cmd!("rustup run stable cargo test -p matrix-sdk-appservice").run()?; + cmd!("rustup run stable cargo nextest run -p matrix-sdk-appservice").run()?; Ok(()) }