Skip to content

Commit 02aa76a

Browse files
authored
Parallelize e2e tests with multiple runners (#2442)
<!-- Reference any GitHub issues resolved by this PR --> ## Introduced changes <!-- A brief description of the changes --> Follow up of this: #2443 ## Checklist <!-- Make sure all of these are complete --> - [ ] Linked relevant issue - [ ] Updated relevant documentation - [ ] Added relevant tests - [ ] Performed self-review of the code - [ ] Added changes to `CHANGELOG.md`
1 parent b739451 commit 02aa76a

File tree

3 files changed

+39
-40
lines changed

3 files changed

+39
-40
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,29 @@ jobs:
2222
- run: cargo test --release --bin snforge
2323
- run: cargo test --release integration -p forge
2424

25+
build-test-forge-e2e-nextest-archive:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: dtolnay/rust-toolchain@stable
30+
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
31+
- name: Install nextest
32+
uses: taiki-e/install-action@nextest
33+
- name: Build and archive tests
34+
run: cargo nextest archive --release -p forge --archive-file nextest-archive.tar.zst
35+
- name: Upload archive to workflow
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: nextest-archive
39+
path: nextest-archive.tar.zst
40+
2541
test-forge-e2e:
2642
name: Test Forge / E2E Tests
2743
runs-on: ubuntu-latest
44+
needs: build-test-forge-e2e-nextest-archive
45+
strategy:
46+
matrix:
47+
partition: [ 1, 2, 3, 4, 5, 6, 7, 8 ]
2848
steps:
2949
- name: Extract branch name
3050
if: github.event_name != 'pull_request'
@@ -57,7 +77,12 @@ jobs:
5777
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
5878
- uses: software-mansion/[email protected]
5979
- uses: software-mansion/setup-universal-sierra-compiler@v1
60-
- run: cargo test --release e2e -p forge
80+
- uses: taiki-e/install-action@nextest
81+
- uses: actions/download-artifact@v4
82+
with:
83+
name: nextest-archive
84+
- name: nextest partition ${{ matrix.partition }}/8
85+
run: cargo nextest run --partition 'count:${{ matrix.partition }}/8' --archive-file 'nextest-archive.tar.zst' e2e
6186

6287
test-forge-runner:
6388
name: Test Forge Runner

crates/forge/tests/e2e/color.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::common::runner::setup_package;
2-
use snapbox::cmd::{cargo_bin, Command as SnapboxCommand, OutputAssert};
1+
use super::common::runner::{setup_package, snforge_test_bin_path};
2+
use snapbox::cmd::{Command as SnapboxCommand, OutputAssert};
33

44
fn runner_color(value: &str) -> SnapboxCommand {
5-
SnapboxCommand::new(cargo_bin!("snforge"))
5+
SnapboxCommand::new(snforge_test_bin_path())
66
.arg("test")
77
.arg("--color")
88
.arg(value)

crates/forge/tests/e2e/common/runner.rs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,30 @@
11
use assert_fs::fixture::{FileWriteStr, PathChild, PathCopy};
22
use assert_fs::TempDir;
33
use camino::Utf8PathBuf;
4-
use fs_extra::dir::{copy, CopyOptions};
54
use indoc::formatdoc;
65
use shared::command::CommandExt;
76
use shared::test_utils::node_url::node_rpc_url;
87
use snapbox::cmd::{cargo_bin, Command as SnapboxCommand};
9-
use std::fs::{create_dir_all, remove_dir_all};
108
use std::path::{Path, PathBuf};
119
use std::process::Command;
1210
use std::str::FromStr;
13-
use std::sync::LazyLock;
1411
use std::{env, fs};
1512
use test_utils::tempdir_with_tool_versions;
1613
use toml_edit::{value, DocumentMut};
1714
use walkdir::WalkDir;
1815

19-
/// To avoid rebuilding `snforge_std` and associated plugin for each test, we cache it in a directory and copy it to the e2e test temp directory.
20-
static BASE_CACHE_DIR: LazyLock<PathBuf> =
21-
LazyLock::new(|| init_base_cache_dir().expect("Failed to initialize base cache directory"));
22-
23-
fn init_base_cache_dir() -> anyhow::Result<PathBuf> {
24-
let cache_dir_path = env::current_dir()?.join(".forge_e2e_cache");
25-
if cache_dir_path.exists() {
26-
remove_dir_all(&cache_dir_path)?;
27-
}
28-
create_dir_all(&cache_dir_path)?;
29-
let cache_dir_path = cache_dir_path.canonicalize()?;
30-
31-
let snforge_std = PathBuf::from("../../snforge_std").canonicalize()?;
32-
33-
SnapboxCommand::new("scarb")
34-
.arg("build")
35-
.current_dir(snforge_std.as_path())
36-
.env("SCARB_CACHE", &cache_dir_path)
37-
.assert()
38-
.success();
39-
40-
Ok(cache_dir_path)
41-
}
42-
4316
pub(crate) fn runner(temp_dir: &TempDir) -> SnapboxCommand {
44-
copy(
45-
BASE_CACHE_DIR.as_path(),
46-
temp_dir.path(),
47-
&CopyOptions::new().overwrite(true).content_only(true),
48-
)
49-
.unwrap();
17+
SnapboxCommand::new(snforge_test_bin_path()).current_dir(temp_dir)
18+
}
5019

51-
SnapboxCommand::new(cargo_bin!("snforge"))
52-
.env("SCARB_CACHE", temp_dir.path())
53-
.current_dir(temp_dir)
20+
// If ran on CI, we want to get the nextest's built binary
21+
pub fn snforge_test_bin_path() -> PathBuf {
22+
if env::var("NEXTEST").unwrap_or("0".to_string()) == "1" {
23+
let snforge_nextest_env =
24+
env::var("NEXTEST_BIN_EXE_snforge").expect("No snforge binary for nextest found");
25+
return PathBuf::from(snforge_nextest_env);
26+
}
27+
cargo_bin!("snforge").to_path_buf()
5428
}
5529

5630
pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand {

0 commit comments

Comments
 (0)