test: Run tests faster with nextest.

> [`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.
This commit is contained in:
Ivan Enderlin
2022-06-20 11:17:59 +02:00
parent 87639a4c4c
commit 399862d955
4 changed files with 20 additions and 5 deletions
+3
View File
@@ -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:
+8 -1
View File
@@ -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 }})
+3
View File
@@ -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:
+6 -4
View File
@@ -164,7 +164,9 @@ fn run_feature_tests(cmd: Option<FeatureSet>) -> 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(())
}