mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-01-02 13:23:13 +00:00
examples: export cucumber Mode and share runner defaults
This commit is contained in:
parent
91c9044abb
commit
bb0378792a
@ -1,19 +1,13 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
time::Duration,
|
||||
};
|
||||
use std::{process, time::Duration};
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use runner_examples::{ChaosBuilderExt as _, ScenarioBuilderExt as _, read_env_any};
|
||||
use runner_examples::{
|
||||
ChaosBuilderExt as _, ScenarioBuilderExt as _, defaults::Mode, demo, read_env_any,
|
||||
};
|
||||
use testing_framework_core::scenario::{Deployer as _, Runner, ScenarioBuilder};
|
||||
use testing_framework_runner_compose::{ComposeDeployer, ComposeRunnerError};
|
||||
use tracing::{info, warn};
|
||||
|
||||
const DEFAULT_VALIDATORS: usize = 1;
|
||||
const DEFAULT_EXECUTORS: usize = 1;
|
||||
const DEFAULT_RUN_SECS: u64 = 60;
|
||||
const MIXED_TXS_PER_BLOCK: u64 = 5;
|
||||
const TOTAL_WALLETS: usize = 1000;
|
||||
const TRANSACTION_WALLETS: usize = 500;
|
||||
@ -30,28 +24,15 @@ const DA_BLOB_RATE: u64 = 1;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
init_node_log_dir_defaults();
|
||||
|
||||
// Compose containers mount KZG params at /kzgrs_test_params; ensure the
|
||||
// generated configs point there unless the caller overrides explicitly.
|
||||
if env::var("NOMOS_KZGRS_PARAMS_PATH").is_err() {
|
||||
// Safe: setting a process-wide environment variable before any threads
|
||||
// or async tasks are spawned.
|
||||
unsafe {
|
||||
env::set_var(
|
||||
"NOMOS_KZGRS_PARAMS_PATH",
|
||||
"/kzgrs_test_params/kzgrs_test_params",
|
||||
);
|
||||
}
|
||||
}
|
||||
runner_examples::defaults::init_node_log_dir_defaults(Mode::Compose);
|
||||
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], DEFAULT_VALIDATORS);
|
||||
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], demo::DEFAULT_VALIDATORS);
|
||||
|
||||
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], DEFAULT_EXECUTORS);
|
||||
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], demo::DEFAULT_EXECUTORS);
|
||||
|
||||
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], DEFAULT_RUN_SECS);
|
||||
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], demo::DEFAULT_RUN_SECS);
|
||||
|
||||
info!(
|
||||
validators,
|
||||
@ -64,35 +45,6 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_node_log_dir_defaults() {
|
||||
if env::var_os("NOMOS_LOG_DIR").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let repo_root = repo_root();
|
||||
let host_dir = repo_root.join("tmp").join("node-logs");
|
||||
let _ = fs::create_dir_all(&host_dir);
|
||||
|
||||
// In compose mode, node processes run inside containers; configs should
|
||||
// point to the container path, while the compose deployer mounts the host
|
||||
// repo's `tmp/node-logs` there.
|
||||
unsafe {
|
||||
env::set_var("NOMOS_LOG_DIR", "/tmp/node-logs");
|
||||
}
|
||||
}
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
env::var("CARGO_WORKSPACE_DIR")
|
||||
.map(PathBuf::from)
|
||||
.ok()
|
||||
.or_else(|| {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
})
|
||||
.expect("repo root must be discoverable from CARGO_WORKSPACE_DIR or CARGO_MANIFEST_DIR")
|
||||
}
|
||||
|
||||
async fn run_compose_case(
|
||||
validators: usize,
|
||||
executors: usize,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use runner_examples::cucumber::{
|
||||
Mode, init_logging_defaults, init_node_log_dir_defaults, init_tracing, run,
|
||||
use runner_examples::{
|
||||
cucumber::run,
|
||||
defaults::{Mode, init_logging_defaults, init_node_log_dir_defaults, init_tracing},
|
||||
};
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use runner_examples::cucumber::{
|
||||
Mode, init_logging_defaults, init_node_log_dir_defaults, init_tracing, run,
|
||||
use runner_examples::{
|
||||
cucumber::run,
|
||||
defaults::{Mode, init_logging_defaults, init_node_log_dir_defaults, init_tracing},
|
||||
};
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::{env, process, time::Duration};
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use runner_examples::{ScenarioBuilderExt as _, read_env_any};
|
||||
use runner_examples::{ScenarioBuilderExt as _, demo, read_env_any};
|
||||
use testing_framework_core::scenario::{
|
||||
Deployer as _, ObservabilityCapability, Runner, ScenarioBuilder,
|
||||
};
|
||||
@ -9,9 +9,6 @@ use testing_framework_runner_k8s::{K8sDeployer, K8sRunnerError};
|
||||
use testing_framework_workflows::ObservabilityBuilderExt as _;
|
||||
use tracing::{info, warn};
|
||||
|
||||
const DEFAULT_RUN_SECS: u64 = 60;
|
||||
const DEFAULT_VALIDATORS: usize = 1;
|
||||
const DEFAULT_EXECUTORS: usize = 1;
|
||||
const MIXED_TXS_PER_BLOCK: u64 = 2;
|
||||
const TOTAL_WALLETS: usize = 200;
|
||||
const TRANSACTION_WALLETS: usize = 50;
|
||||
@ -21,9 +18,9 @@ const DA_BLOB_RATE: u64 = 1;
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], DEFAULT_VALIDATORS);
|
||||
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], DEFAULT_EXECUTORS);
|
||||
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], DEFAULT_RUN_SECS);
|
||||
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], demo::DEFAULT_VALIDATORS);
|
||||
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], demo::DEFAULT_EXECUTORS);
|
||||
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], demo::DEFAULT_RUN_SECS);
|
||||
info!(validators, executors, run_secs, "starting k8s runner demo");
|
||||
|
||||
if let Err(err) = run_k8s_case(validators, executors, Duration::from_secs(run_secs)).await {
|
||||
|
||||
@ -1,19 +1,11 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
time::Duration,
|
||||
};
|
||||
use std::{env, process, time::Duration};
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use runner_examples::{ScenarioBuilderExt as _, read_env_any};
|
||||
use runner_examples::{ScenarioBuilderExt as _, defaults::Mode, demo, read_env_any};
|
||||
use testing_framework_core::scenario::{Deployer as _, Runner, ScenarioBuilder};
|
||||
use testing_framework_runner_local::LocalDeployer;
|
||||
use tracing::{info, warn};
|
||||
|
||||
const DEFAULT_VALIDATORS: usize = 1;
|
||||
const DEFAULT_EXECUTORS: usize = 1;
|
||||
const DEFAULT_RUN_SECS: u64 = 60;
|
||||
const MIXED_TXS_PER_BLOCK: u64 = 5;
|
||||
const TOTAL_WALLETS: usize = 1000;
|
||||
const TRANSACTION_WALLETS: usize = 500;
|
||||
@ -22,7 +14,7 @@ const SMOKE_RUN_SECS_MAX: u64 = 30;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
init_node_log_dir_defaults();
|
||||
runner_examples::defaults::init_node_log_dir_defaults(Mode::Host);
|
||||
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
@ -31,9 +23,9 @@ async fn main() {
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], DEFAULT_VALIDATORS);
|
||||
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], DEFAULT_EXECUTORS);
|
||||
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], DEFAULT_RUN_SECS);
|
||||
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], demo::DEFAULT_VALIDATORS);
|
||||
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], demo::DEFAULT_EXECUTORS);
|
||||
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], demo::DEFAULT_RUN_SECS);
|
||||
|
||||
info!(
|
||||
validators,
|
||||
@ -46,30 +38,6 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_node_log_dir_defaults() {
|
||||
if env::var_os("NOMOS_LOG_DIR").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let host_dir = repo_root().join("tmp").join("node-logs");
|
||||
let _ = fs::create_dir_all(&host_dir);
|
||||
unsafe {
|
||||
env::set_var("NOMOS_LOG_DIR", host_dir);
|
||||
}
|
||||
}
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
env::var("CARGO_WORKSPACE_DIR")
|
||||
.map(PathBuf::from)
|
||||
.ok()
|
||||
.or_else(|| {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
})
|
||||
.expect("repo root must be discoverable from CARGO_WORKSPACE_DIR or CARGO_MANIFEST_DIR")
|
||||
}
|
||||
|
||||
async fn run_local_case(validators: usize, executors: usize, run_duration: Duration) -> Result<()> {
|
||||
info!(
|
||||
validators,
|
||||
|
||||
@ -1,29 +1,11 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use cucumber::World;
|
||||
use cucumber_ext::TestingFrameworkWorld;
|
||||
use tracing_subscriber::{EnvFilter, fmt};
|
||||
|
||||
pub use crate::defaults::Mode;
|
||||
|
||||
const FEATURES_PATH: &str = "examples/cucumber/features";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Mode {
|
||||
Host,
|
||||
Compose,
|
||||
}
|
||||
|
||||
fn set_default_env(key: &str, value: &str) {
|
||||
if std::env::var_os(key).is_none() {
|
||||
// SAFETY: Used as an early-run default. Prefer setting env vars in the
|
||||
// shell for multi-threaded runs.
|
||||
unsafe {
|
||||
std::env::set_var(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use crate::defaults::{init_logging_defaults, init_node_log_dir_defaults, init_tracing};
|
||||
|
||||
fn is_compose(
|
||||
feature: &cucumber::gherkin::Feature,
|
||||
@ -33,44 +15,6 @@ fn is_compose(
|
||||
|| feature.tags.iter().any(|tag| tag == "compose")
|
||||
}
|
||||
|
||||
pub fn init_logging_defaults() {
|
||||
set_default_env("POL_PROOF_DEV_MODE", "true");
|
||||
set_default_env("NOMOS_TESTS_KEEP_LOGS", "1");
|
||||
set_default_env("NOMOS_LOG_LEVEL", "info");
|
||||
set_default_env("RUST_LOG", "info");
|
||||
}
|
||||
|
||||
pub fn init_node_log_dir_defaults(mode: Mode) {
|
||||
if env::var_os("NOMOS_LOG_DIR").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let host_dir = repo_root().join("tmp").join("node-logs");
|
||||
let _ = fs::create_dir_all(&host_dir);
|
||||
|
||||
match mode {
|
||||
Mode::Host => set_default_env("NOMOS_LOG_DIR", &host_dir.display().to_string()),
|
||||
Mode::Compose => set_default_env("NOMOS_LOG_DIR", "/tmp/node-logs"),
|
||||
}
|
||||
}
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
env::var("CARGO_WORKSPACE_DIR")
|
||||
.map(PathBuf::from)
|
||||
.ok()
|
||||
.or_else(|| {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
})
|
||||
.expect("repo root must be discoverable from CARGO_WORKSPACE_DIR or CARGO_MANIFEST_DIR")
|
||||
}
|
||||
|
||||
pub fn init_tracing() {
|
||||
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
|
||||
let _ = fmt().with_env_filter(filter).with_target(true).try_init();
|
||||
}
|
||||
|
||||
pub async fn run(mode: Mode) {
|
||||
TestingFrameworkWorld::cucumber()
|
||||
.with_default_cli()
|
||||
|
||||
63
examples/src/defaults.rs
Normal file
63
examples/src/defaults.rs
Normal file
@ -0,0 +1,63 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use tracing_subscriber::{EnvFilter, fmt};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Mode {
|
||||
Host,
|
||||
Compose,
|
||||
}
|
||||
|
||||
const DEFAULT_NODE_LOG_DIR_REL: &str = ".tmp/node-logs";
|
||||
const DEFAULT_CONTAINER_NODE_LOG_DIR: &str = "/tmp/node-logs";
|
||||
|
||||
fn set_default_env(key: &str, value: &str) {
|
||||
if std::env::var_os(key).is_none() {
|
||||
// SAFETY: Used as an early-run default. Prefer setting env vars in the
|
||||
// shell for multi-threaded runs.
|
||||
unsafe {
|
||||
std::env::set_var(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_logging_defaults() {
|
||||
set_default_env("POL_PROOF_DEV_MODE", "true");
|
||||
set_default_env("NOMOS_TESTS_KEEP_LOGS", "1");
|
||||
set_default_env("NOMOS_LOG_LEVEL", "info");
|
||||
set_default_env("RUST_LOG", "info");
|
||||
}
|
||||
|
||||
pub fn init_node_log_dir_defaults(mode: Mode) {
|
||||
if env::var_os("NOMOS_LOG_DIR").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let host_dir = repo_root().join(DEFAULT_NODE_LOG_DIR_REL);
|
||||
let _ = fs::create_dir_all(&host_dir);
|
||||
|
||||
match mode {
|
||||
Mode::Host => set_default_env("NOMOS_LOG_DIR", &host_dir.display().to_string()),
|
||||
Mode::Compose => set_default_env("NOMOS_LOG_DIR", DEFAULT_CONTAINER_NODE_LOG_DIR),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_tracing() {
|
||||
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
|
||||
let _ = fmt().with_env_filter(filter).with_target(true).try_init();
|
||||
}
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
env::var("CARGO_WORKSPACE_DIR")
|
||||
.map(PathBuf::from)
|
||||
.ok()
|
||||
.or_else(|| {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
})
|
||||
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")))
|
||||
}
|
||||
3
examples/src/demo.rs
Normal file
3
examples/src/demo.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub const DEFAULT_VALIDATORS: usize = 1;
|
||||
pub const DEFAULT_EXECUTORS: usize = 1;
|
||||
pub const DEFAULT_RUN_SECS: u64 = 60;
|
||||
@ -1,4 +1,6 @@
|
||||
pub mod cucumber;
|
||||
pub mod defaults;
|
||||
pub mod demo;
|
||||
pub mod env;
|
||||
|
||||
pub use env::read_env_any;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user