-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): Add zk_supervisor run unit tests command (#2610)
## What ❔ Add zk_supervisor run unit tests command --------- Signed-off-by: Danil <[email protected]> Co-authored-by: Danil <[email protected]>
- Loading branch information
1 parent
8e8877e
commit 93d0abc
Showing
12 changed files
with
180 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod integration; | ||
pub mod recovery; | ||
pub mod revert; | ||
pub mod rust; |
9 changes: 9 additions & 0 deletions
9
zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use clap::Parser; | ||
|
||
use crate::messages::MSG_TEST_RUST_OPTIONS_HELP; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct RustArgs { | ||
#[clap(long, help = MSG_TEST_RUST_OPTIONS_HELP)] | ||
pub options: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use anyhow::Context; | ||
use common::{cmd::Cmd, db::wait_for_db, logger}; | ||
use config::EcosystemConfig; | ||
use xshell::{cmd, Shell}; | ||
|
||
use super::args::rust::RustArgs; | ||
use crate::{ | ||
commands::database, | ||
dals::get_test_dals, | ||
messages::{ | ||
MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, | ||
MSG_RESETTING_TEST_DATABASES, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, | ||
}, | ||
}; | ||
|
||
pub async fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { | ||
let ecosystem = EcosystemConfig::from_file(shell)?; | ||
let chain = ecosystem | ||
.clone() | ||
.load_chain(Some(ecosystem.default_chain)) | ||
.context(MSG_CHAIN_NOT_FOUND_ERR)?; | ||
let general_config = chain.get_general_config()?; | ||
let postgres = general_config | ||
.postgres_config | ||
.context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?; | ||
|
||
reset_test_databases(shell).await?; | ||
|
||
let _dir_guard = shell.push_dir(&ecosystem.link_to_code); | ||
|
||
let cmd = if nextest_is_installed(shell)? { | ||
logger::info(MSG_USING_CARGO_NEXTEST); | ||
cmd!(shell, "cargo nextest run --release") | ||
} else { | ||
logger::error(MSG_CARGO_NEXTEST_MISSING_ERR); | ||
cmd!(shell, "cargo test --release") | ||
}; | ||
|
||
let cmd = if let Some(options) = args.options { | ||
Cmd::new(cmd.args(options.split_whitespace())).with_force_run() | ||
} else { | ||
Cmd::new(cmd).with_force_run() | ||
}; | ||
|
||
let cmd = cmd | ||
.env( | ||
"TEST_DATABASE_URL", | ||
postgres | ||
.test_server_url | ||
.context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, | ||
) | ||
.env( | ||
"TEST_PROVER_DATABASE_URL", | ||
postgres | ||
.test_prover_url | ||
.context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, | ||
); | ||
cmd.run()?; | ||
|
||
logger::outro(MSG_UNIT_TESTS_RUN_SUCCESS); | ||
Ok(()) | ||
} | ||
|
||
fn nextest_is_installed(shell: &Shell) -> anyhow::Result<bool> { | ||
let out = String::from_utf8( | ||
Cmd::new(cmd!(shell, "cargo install --list")) | ||
.run_with_output()? | ||
.stdout, | ||
)?; | ||
Ok(out.contains("cargo-nextest")) | ||
} | ||
|
||
async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { | ||
logger::info(MSG_RESETTING_TEST_DATABASES); | ||
let ecosystem = EcosystemConfig::from_file(shell)?; | ||
|
||
Cmd::new(cmd!( | ||
shell, | ||
"docker compose -f docker-compose-unit-tests.yml down" | ||
)) | ||
.run()?; | ||
Cmd::new(cmd!( | ||
shell, | ||
"docker compose -f docker-compose-unit-tests.yml up -d" | ||
)) | ||
.run()?; | ||
|
||
for dal in get_test_dals(shell)? { | ||
let mut url = dal.url.clone(); | ||
url.set_path(""); | ||
wait_for_db(&url, 3).await?; | ||
database::reset::reset_database(shell, ecosystem.link_to_code.clone(), dal.clone()).await?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters