From 7e544c8838e03ef3d6deca14062f68bf82aa83dc Mon Sep 17 00:00:00 2001 From: andrussal Date: Wed, 3 Dec 2025 05:52:14 +0100 Subject: [PATCH] Add *_with helpers for DSL blocks and apply to examples --- examples/src/bin/compose_runner.rs | 31 +++++++------- examples/src/bin/k8s_runner.rs | 16 +++---- examples/src/bin/local_runner.rs | 16 +++---- .../workflows/src/builder/mod.rs | 42 +++++++++++++++++++ 4 files changed, 74 insertions(+), 31 deletions(-) diff --git a/examples/src/bin/compose_runner.rs b/examples/src/bin/compose_runner.rs index db3b33b..578544f 100644 --- a/examples/src/bin/compose_runner.rs +++ b/examples/src/bin/compose_runner.rs @@ -49,22 +49,23 @@ async fn run_compose_case( .executors(executors) }) .enable_node_control() - .chaos() - .restart() - // Keep chaos restarts outside the test run window to avoid crash loops on restart. - .min_delay(Duration::from_secs(120)) - .max_delay(Duration::from_secs(180)) - .target_cooldown(Duration::from_secs(240)) - .apply() + .chaos_with(|c| { + c.restart() + // Keep chaos restarts outside the test run window to avoid crash loops on restart. + .min_delay(Duration::from_secs(120)) + .max_delay(Duration::from_secs(180)) + .target_cooldown(Duration::from_secs(240)) + .apply() + }) .wallets(TOTAL_WALLETS) - .transactions() - .rate(MIXED_TXS_PER_BLOCK) - .users(TRANSACTION_WALLETS) - .apply() - .da() - .channel_rate(1) - .blob_rate(1) - .apply() + .transactions_with(|txs| { + txs.rate(MIXED_TXS_PER_BLOCK) + .users(TRANSACTION_WALLETS) + }) + .da_with(|da| { + da.channel_rate(1) + .blob_rate(1) + }) .with_run_duration(run_duration) .expect_consensus_liveness() .build(); diff --git a/examples/src/bin/k8s_runner.rs b/examples/src/bin/k8s_runner.rs index 34522ef..2a0c2a5 100644 --- a/examples/src/bin/k8s_runner.rs +++ b/examples/src/bin/k8s_runner.rs @@ -45,14 +45,14 @@ async fn run_k8s_case( .executors(executors) }) .wallets(TOTAL_WALLETS) - .transactions() - .rate(MIXED_TXS_PER_BLOCK) - .users(TRANSACTION_WALLETS) - .apply() - .da() - .channel_rate(1) - .blob_rate(1) - .apply() + .transactions_with(|txs| { + txs.rate(MIXED_TXS_PER_BLOCK) + .users(TRANSACTION_WALLETS) + }) + .da_with(|da| { + da.channel_rate(1) + .blob_rate(1) + }) .with_run_duration(run_duration) .expect_consensus_liveness() .build(); diff --git a/examples/src/bin/local_runner.rs b/examples/src/bin/local_runner.rs index cb67c30..1e71f08 100644 --- a/examples/src/bin/local_runner.rs +++ b/examples/src/bin/local_runner.rs @@ -53,14 +53,14 @@ async fn run_local_case( .executors(executors) }) .wallets(TOTAL_WALLETS) - .transactions() - .rate(MIXED_TXS_PER_BLOCK) - .users(TRANSACTION_WALLETS) - .apply() - .da() - .channel_rate(1) - .blob_rate(1) - .apply() + .transactions_with(|txs| { + txs.rate(MIXED_TXS_PER_BLOCK) + .users(TRANSACTION_WALLETS) + }) + .da_with(|da| { + da.channel_rate(1) + .blob_rate(1) + }) .with_run_duration(run_duration) .expect_consensus_liveness() .build(); diff --git a/testing-framework/workflows/src/builder/mod.rs b/testing-framework/workflows/src/builder/mod.rs index b7a2a48..752a55c 100644 --- a/testing-framework/workflows/src/builder/mod.rs +++ b/testing-framework/workflows/src/builder/mod.rs @@ -35,8 +35,18 @@ non_zero_rate_fn!(blob_rate_checked, "blob rate must be non-zero"); pub trait ScenarioBuilderExt: Sized { /// Configure a transaction flow workload. fn transactions(self) -> TransactionFlowBuilder; + /// Configure a transaction flow workload via closure. + fn transactions_with( + self, + f: impl FnOnce(TransactionFlowBuilder) -> TransactionFlowBuilder, + ) -> CoreScenarioBuilder; /// Configure a data-availability workload. fn da(self) -> DataAvailabilityFlowBuilder; + /// Configure a data-availability workload via closure. + fn da_with( + self, + f: impl FnOnce(DataAvailabilityFlowBuilder) -> DataAvailabilityFlowBuilder, + ) -> CoreScenarioBuilder; #[must_use] /// Attach a consensus liveness expectation. fn expect_consensus_liveness(self) -> Self; @@ -50,10 +60,24 @@ impl ScenarioBuilderExt for CoreScenarioBuilder { TransactionFlowBuilder::new(self) } + fn transactions_with( + self, + f: impl FnOnce(TransactionFlowBuilder) -> TransactionFlowBuilder, + ) -> CoreScenarioBuilder { + f(self.transactions()).apply() + } + fn da(self) -> DataAvailabilityFlowBuilder { DataAvailabilityFlowBuilder::new(self) } + fn da_with( + self, + f: impl FnOnce(DataAvailabilityFlowBuilder) -> DataAvailabilityFlowBuilder, + ) -> CoreScenarioBuilder { + f(self.da()).apply() + } + fn expect_consensus_liveness(self) -> Self { self.with_expectation(ConsensusLiveness::default()) } @@ -185,12 +209,24 @@ impl DataAvailabilityFlowBuilder { pub trait ChaosBuilderExt: Sized { /// Entry point into chaos workloads. fn chaos(self) -> ChaosBuilder; + /// Configure chaos via closure. + fn chaos_with( + self, + f: impl FnOnce(ChaosBuilder) -> CoreScenarioBuilder, + ) -> CoreScenarioBuilder; } impl ChaosBuilderExt for CoreScenarioBuilder { fn chaos(self) -> ChaosBuilder { ChaosBuilder { builder: self } } + + fn chaos_with( + self, + f: impl FnOnce(ChaosBuilder) -> CoreScenarioBuilder, + ) -> CoreScenarioBuilder { + f(self.chaos()) + } } /// Chaos workload builder root. @@ -202,6 +238,12 @@ pub struct ChaosBuilder { } impl ChaosBuilder { + /// Finish without adding a chaos workload. + #[must_use] + pub fn apply(self) -> CoreScenarioBuilder { + self.builder + } + /// Configure a random restarts chaos workload. #[must_use] pub fn restart(self) -> ChaosRestartBuilder {