mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-01-02 13:23:13 +00:00
566 lines
28 KiB
HTML
566 lines
28 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="en" class="light" dir="ltr">
|
|
<head>
|
|
<!-- Book generated using mdBook -->
|
|
<meta charset="UTF-8">
|
|
<title>Extending the Framework - Logos Blockchain Testing Framework Book</title>
|
|
|
|
|
|
<!-- Custom HTML head -->
|
|
|
|
<meta name="description" content="">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="theme-color" content="#ffffff">
|
|
|
|
<link rel="icon" href="favicon.svg">
|
|
<link rel="shortcut icon" href="favicon.png">
|
|
<link rel="stylesheet" href="css/variables.css">
|
|
<link rel="stylesheet" href="css/general.css">
|
|
<link rel="stylesheet" href="css/chrome.css">
|
|
<link rel="stylesheet" href="css/print.css" media="print">
|
|
|
|
<!-- Fonts -->
|
|
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
|
|
<link rel="stylesheet" href="fonts/fonts.css">
|
|
|
|
<!-- Highlight.js Stylesheets -->
|
|
<link rel="stylesheet" href="highlight.css">
|
|
<link rel="stylesheet" href="tomorrow-night.css">
|
|
<link rel="stylesheet" href="ayu-highlight.css">
|
|
|
|
<!-- Custom theme stylesheets -->
|
|
|
|
</head>
|
|
<body class="sidebar-visible no-js">
|
|
<div id="body-container">
|
|
<!-- Provide site root to javascript -->
|
|
<script>
|
|
var path_to_root = "";
|
|
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
|
|
</script>
|
|
|
|
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
|
<script>
|
|
try {
|
|
var theme = localStorage.getItem('mdbook-theme');
|
|
var sidebar = localStorage.getItem('mdbook-sidebar');
|
|
|
|
if (theme.startsWith('"') && theme.endsWith('"')) {
|
|
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
|
|
}
|
|
|
|
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
|
|
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
|
|
}
|
|
} catch (e) { }
|
|
</script>
|
|
|
|
<!-- Set the theme before any content is loaded, prevents flash -->
|
|
<script>
|
|
var theme;
|
|
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
|
if (theme === null || theme === undefined) { theme = default_theme; }
|
|
var html = document.querySelector('html');
|
|
html.classList.remove('light')
|
|
html.classList.add(theme);
|
|
var body = document.querySelector('body');
|
|
body.classList.remove('no-js')
|
|
body.classList.add('js');
|
|
</script>
|
|
|
|
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
|
|
|
|
<!-- Hide / unhide sidebar before it is displayed -->
|
|
<script>
|
|
var body = document.querySelector('body');
|
|
var sidebar = null;
|
|
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
|
|
if (document.body.clientWidth >= 1080) {
|
|
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
|
sidebar = sidebar || 'visible';
|
|
} else {
|
|
sidebar = 'hidden';
|
|
}
|
|
sidebar_toggle.checked = sidebar === 'visible';
|
|
body.classList.remove('sidebar-visible');
|
|
body.classList.add("sidebar-" + sidebar);
|
|
</script>
|
|
|
|
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
|
<div class="sidebar-scrollbox">
|
|
<ol class="chapter"><li class="chapter-item expanded "><a href="project-context-primer.html"><strong aria-hidden="true">1.</strong> Project Context Primer</a></li><li class="chapter-item expanded "><a href="what-you-will-learn.html"><strong aria-hidden="true">2.</strong> What You Will Learn</a></li><li class="chapter-item expanded "><a href="quickstart.html"><strong aria-hidden="true">3.</strong> Quickstart</a></li><li class="chapter-item expanded "><a href="part-i.html"><strong aria-hidden="true">4.</strong> Part I — Foundations</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="introduction.html"><strong aria-hidden="true">4.1.</strong> Introduction</a></li><li class="chapter-item expanded "><a href="architecture-overview.html"><strong aria-hidden="true">4.2.</strong> Architecture Overview</a></li><li class="chapter-item expanded "><a href="testing-philosophy.html"><strong aria-hidden="true">4.3.</strong> Testing Philosophy</a></li><li class="chapter-item expanded "><a href="scenario-lifecycle.html"><strong aria-hidden="true">4.4.</strong> Scenario Lifecycle</a></li><li class="chapter-item expanded "><a href="design-rationale.html"><strong aria-hidden="true">4.5.</strong> Design Rationale</a></li></ol></li><li class="chapter-item expanded "><a href="part-ii.html"><strong aria-hidden="true">5.</strong> Part II — User Guide</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="workspace-layout.html"><strong aria-hidden="true">5.1.</strong> Workspace Layout</a></li><li class="chapter-item expanded "><a href="annotated-tree.html"><strong aria-hidden="true">5.2.</strong> Annotated Tree</a></li><li class="chapter-item expanded "><a href="authoring-scenarios.html"><strong aria-hidden="true">5.3.</strong> Authoring Scenarios</a></li><li class="chapter-item expanded "><a href="workloads.html"><strong aria-hidden="true">5.4.</strong> Core Content: Workloads & Expectations</a></li><li class="chapter-item expanded "><a href="scenario-builder-ext-patterns.html"><strong aria-hidden="true">5.5.</strong> Core Content: ScenarioBuilderExt Patterns</a></li><li class="chapter-item expanded "><a href="best-practices.html"><strong aria-hidden="true">5.6.</strong> Best Practices</a></li><li class="chapter-item expanded "><a href="usage-patterns.html"><strong aria-hidden="true">5.7.</strong> Usage Patterns</a></li><li class="chapter-item expanded "><a href="examples.html"><strong aria-hidden="true">5.8.</strong> Examples</a></li><li class="chapter-item expanded "><a href="examples-advanced.html"><strong aria-hidden="true">5.9.</strong> Advanced & Artificial Examples</a></li><li class="chapter-item expanded "><a href="cucumber-bdd.html"><strong aria-hidden="true">5.10.</strong> Cucumber/BDD Interface</a></li><li class="chapter-item expanded "><a href="running-scenarios.html"><strong aria-hidden="true">5.11.</strong> Running Scenarios</a></li><li class="chapter-item expanded "><a href="runners.html"><strong aria-hidden="true">5.12.</strong> Runners</a></li><li class="chapter-item expanded "><a href="node-control.html"><strong aria-hidden="true">5.13.</strong> RunContext: BlockFeed & Node Control</a></li><li class="chapter-item expanded "><a href="chaos.html"><strong aria-hidden="true">5.14.</strong> Chaos Workloads</a></li><li class="chapter-item expanded "><a href="topology-chaos.html"><strong aria-hidden="true">5.15.</strong> Topology & Chaos Patterns</a></li></ol></li><li class="chapter-item expanded "><a href="part-iii.html"><strong aria-hidden="true">6.</strong> Part III — Developer Reference</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="scenario-model.html"><strong aria-hidden="true">6.1.</strong> Scenario Model (Developer Level)</a></li><li class="chapter-item expanded "><a href="api-levels.html"><strong aria-hidden="true">6.2.</strong> API Levels: Builder DSL vs. Direct</a></li><li class="chapter-item expanded "><a href="extending.html" class="active"><strong aria-hidden="true">6.3.</strong> Extending the Framework</a></li><li class="chapter-item expanded "><a href="custom-workload-example.html"><strong aria-hidden="true">6.4.</strong> Example: New Workload & Expectation (Rust)</a></li><li class="chapter-item expanded "><a href="internal-crate-reference.html"><strong aria-hidden="true">6.5.</strong> Internal Crate Reference</a></li></ol></li><li class="chapter-item expanded "><a href="part-iv.html"><strong aria-hidden="true">7.</strong> Part IV — Operations & Deployment</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="operations-overview.html"><strong aria-hidden="true">7.1.</strong> Overview</a></li><li class="chapter-item expanded "><a href="prerequisites.html"><strong aria-hidden="true">7.2.</strong> Prerequisites & Setup</a></li><li class="chapter-item expanded "><a href="running-examples.html"><strong aria-hidden="true">7.3.</strong> Running Examples</a></li><li class="chapter-item expanded "><a href="ci-integration.html"><strong aria-hidden="true">7.4.</strong> CI Integration</a></li><li class="chapter-item expanded "><a href="environment-variables.html"><strong aria-hidden="true">7.5.</strong> Environment Variables</a></li><li class="chapter-item expanded "><a href="logging-observability.html"><strong aria-hidden="true">7.6.</strong> Logging & Observability</a></li></ol></li><li class="chapter-item expanded "><a href="part-v.html"><strong aria-hidden="true">8.</strong> Part V — Appendix</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="dsl-cheat-sheet.html"><strong aria-hidden="true">8.1.</strong> Builder API Quick Reference</a></li><li class="chapter-item expanded "><a href="troubleshooting.html"><strong aria-hidden="true">8.2.</strong> Troubleshooting Scenarios</a></li><li class="chapter-item expanded "><a href="faq.html"><strong aria-hidden="true">8.3.</strong> FAQ</a></li><li class="chapter-item expanded "><a href="glossary.html"><strong aria-hidden="true">8.4.</strong> Glossary</a></li></ol></li></ol>
|
|
</div>
|
|
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
|
|
<div class="sidebar-resize-indicator"></div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Track and set sidebar scroll position -->
|
|
<script>
|
|
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
|
|
sidebarScrollbox.addEventListener('click', function(e) {
|
|
if (e.target.tagName === 'A') {
|
|
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
|
|
}
|
|
}, { passive: true });
|
|
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
|
|
sessionStorage.removeItem('sidebar-scroll');
|
|
if (sidebarScrollTop) {
|
|
// preserve sidebar scroll position when navigating via links within sidebar
|
|
sidebarScrollbox.scrollTop = sidebarScrollTop;
|
|
} else {
|
|
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
|
|
var activeSection = document.querySelector('#sidebar .active');
|
|
if (activeSection) {
|
|
activeSection.scrollIntoView({ block: 'center' });
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<div id="page-wrapper" class="page-wrapper">
|
|
|
|
<div class="page">
|
|
<div id="menu-bar-hover-placeholder"></div>
|
|
<div id="menu-bar" class="menu-bar sticky">
|
|
<div class="left-buttons">
|
|
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
|
<i class="fa fa-bars"></i>
|
|
</label>
|
|
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
|
<i class="fa fa-paint-brush"></i>
|
|
</button>
|
|
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
|
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
|
</ul>
|
|
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
|
<i class="fa fa-search"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<h1 class="menu-title">Logos Blockchain Testing Framework Book</h1>
|
|
|
|
<div class="right-buttons">
|
|
<a href="print.html" title="Print this book" aria-label="Print this book">
|
|
<i id="print-button" class="fa fa-print"></i>
|
|
</a>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div id="search-wrapper" class="hidden">
|
|
<form id="searchbar-outer" class="searchbar-outer">
|
|
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
|
</form>
|
|
<div id="searchresults-outer" class="searchresults-outer hidden">
|
|
<div id="searchresults-header" class="searchresults-header"></div>
|
|
<ul id="searchresults">
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
|
<script>
|
|
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
|
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
|
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
|
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
|
});
|
|
</script>
|
|
|
|
<div id="content" class="content">
|
|
<main>
|
|
<h1 id="extending-the-framework"><a class="header" href="#extending-the-framework">Extending the Framework</a></h1>
|
|
<p>This guide shows how to extend the framework with custom workloads, expectations, runners, and topology helpers. Each section includes the trait outline and a minimal code example.</p>
|
|
<h2 id="adding-a-workload"><a class="header" href="#adding-a-workload">Adding a Workload</a></h2>
|
|
<p><strong>Steps:</strong></p>
|
|
<ol>
|
|
<li>Implement <code>testing_framework_core::scenario::Workload</code></li>
|
|
<li>Provide a name and any bundled expectations</li>
|
|
<li>Use <code>init</code> to derive inputs from topology/metrics; fail fast if prerequisites missing</li>
|
|
<li>Use <code>start</code> to drive async traffic using <code>RunContext</code> clients</li>
|
|
<li>Expose from <code>testing-framework/workflows</code> and optionally add a DSL helper</li>
|
|
</ol>
|
|
<p><strong>Trait outline:</strong></p>
|
|
<pre><code class="language-rust ignore">use async_trait::async_trait;
|
|
use testing_framework_core::scenario::{
|
|
DynError, Expectation, RunContext, RunMetrics, Workload,
|
|
};
|
|
use testing_framework_core::topology::generation::GeneratedTopology;
|
|
|
|
struct MyExpectation;
|
|
|
|
#[async_trait]
|
|
impl Expectation for MyExpectation {
|
|
fn name(&self) -> &str {
|
|
"my_expectation"
|
|
}
|
|
|
|
async fn evaluate(&mut self, _ctx: &RunContext) -> Result<(), DynError> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub struct MyWorkload {
|
|
// Configuration fields
|
|
target_rate: u64,
|
|
}
|
|
|
|
impl MyWorkload {
|
|
pub fn new(target_rate: u64) -> Self {
|
|
Self { target_rate }
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl Workload for MyWorkload {
|
|
fn name(&self) -> &str {
|
|
"my_workload"
|
|
}
|
|
|
|
fn expectations(&self) -> Vec<Box<dyn Expectation>> {
|
|
// Return bundled expectations that should run with this workload
|
|
vec![Box::new(MyExpectation)]
|
|
}
|
|
|
|
fn init(
|
|
&mut self,
|
|
topology: &GeneratedTopology,
|
|
_run_metrics: &RunMetrics,
|
|
) -> Result<(), DynError> {
|
|
// Validate prerequisites (e.g., enough nodes, wallet data present)
|
|
if topology.validators().is_empty() {
|
|
return Err("no validators available".into());
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
async fn start(&self, ctx: &RunContext) -> Result<(), DynError> {
|
|
// Drive async activity: submit transactions, query nodes, etc.
|
|
let clients = ctx.node_clients().validator_clients();
|
|
|
|
for client in clients {
|
|
let info = client.consensus_info().await?;
|
|
tracing::info!(height = info.height, "workload queried node");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}</code></pre>
|
|
<p><strong>Key points:</strong></p>
|
|
<ul>
|
|
<li><code>name()</code> identifies the workload in logs</li>
|
|
<li><code>expectations()</code> bundles default checks (can be empty)</li>
|
|
<li><code>init()</code> validates topology before run starts</li>
|
|
<li><code>start()</code> executes concurrently with other workloads; it should complete before run duration expires</li>
|
|
</ul>
|
|
<p>See <a href="custom-workload-example.html">Example: New Workload & Expectation</a> for a complete, runnable example.</p>
|
|
<h2 id="adding-an-expectation"><a class="header" href="#adding-an-expectation">Adding an Expectation</a></h2>
|
|
<p><strong>Steps:</strong></p>
|
|
<ol>
|
|
<li>Implement <code>testing_framework_core::scenario::Expectation</code></li>
|
|
<li>Use <code>start_capture</code> to snapshot baseline metrics (optional)</li>
|
|
<li>Use <code>evaluate</code> to assert outcomes after workloads finish</li>
|
|
<li>Return descriptive errors; the runner aggregates them</li>
|
|
<li>Export from <code>testing-framework/workflows</code> if reusable</li>
|
|
</ol>
|
|
<p><strong>Trait outline:</strong></p>
|
|
<pre><code class="language-rust ignore">use async_trait::async_trait;
|
|
use testing_framework_core::scenario::{DynError, Expectation, RunContext};
|
|
|
|
pub struct MyExpectation {
|
|
expected_value: u64,
|
|
captured_baseline: Option<u64>,
|
|
}
|
|
|
|
impl MyExpectation {
|
|
pub fn new(expected_value: u64) -> Self {
|
|
Self {
|
|
expected_value,
|
|
captured_baseline: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl Expectation for MyExpectation {
|
|
fn name(&self) -> &str {
|
|
"my_expectation"
|
|
}
|
|
|
|
async fn start_capture(&mut self, ctx: &RunContext) -> Result<(), DynError> {
|
|
// Optional: capture baseline state before workloads start
|
|
let client = ctx.node_clients().validator_clients().first()
|
|
.ok_or("no validators")?;
|
|
|
|
let info = client.consensus_info().await?;
|
|
self.captured_baseline = Some(info.height);
|
|
|
|
tracing::info!(baseline = self.captured_baseline, "captured baseline");
|
|
Ok(())
|
|
}
|
|
|
|
async fn evaluate(&mut self, ctx: &RunContext) -> Result<(), DynError> {
|
|
// Assert the expected condition holds after workloads finish
|
|
let client = ctx.node_clients().validator_clients().first()
|
|
.ok_or("no validators")?;
|
|
|
|
let info = client.consensus_info().await?;
|
|
let final_height = info.height;
|
|
|
|
let baseline = self.captured_baseline.unwrap_or(0);
|
|
let delta = final_height.saturating_sub(baseline);
|
|
|
|
if delta < self.expected_value {
|
|
return Err(format!(
|
|
"expected at least {} blocks, got {}",
|
|
self.expected_value, delta
|
|
).into());
|
|
}
|
|
|
|
tracing::info!(delta, "expectation passed");
|
|
Ok(())
|
|
}
|
|
}</code></pre>
|
|
<p><strong>Key points:</strong></p>
|
|
<ul>
|
|
<li><code>name()</code> identifies the expectation in logs</li>
|
|
<li><code>start_capture()</code> runs before workloads start (optional)</li>
|
|
<li><code>evaluate()</code> runs after workloads finish; return descriptive errors</li>
|
|
<li>Expectations run sequentially; keep them fast</li>
|
|
</ul>
|
|
<h2 id="adding-a-runner-deployer"><a class="header" href="#adding-a-runner-deployer">Adding a Runner (Deployer)</a></h2>
|
|
<p><strong>Steps:</strong></p>
|
|
<ol>
|
|
<li>Implement <code>testing_framework_core::scenario::Deployer<Caps></code> for your capability type</li>
|
|
<li>Deploy infrastructure and return a <code>Runner</code></li>
|
|
<li>Construct <code>NodeClients</code> and spawn a <code>BlockFeed</code></li>
|
|
<li>Build a <code>RunContext</code> and provide a <code>CleanupGuard</code> for teardown</li>
|
|
</ol>
|
|
<p><strong>Trait outline:</strong></p>
|
|
<pre><code class="language-rust ignore">use async_trait::async_trait;
|
|
use testing_framework_core::scenario::{
|
|
CleanupGuard, Deployer, DynError, Metrics, NodeClients, RunContext, Runner, Scenario,
|
|
spawn_block_feed,
|
|
};
|
|
use testing_framework_core::topology::deployment::Topology;
|
|
|
|
pub struct MyDeployer {
|
|
// Configuration: cluster connection details, etc.
|
|
}
|
|
|
|
impl MyDeployer {
|
|
pub fn new() -> Self {
|
|
Self {}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl Deployer<()> for MyDeployer {
|
|
type Error = DynError;
|
|
|
|
async fn deploy(&self, scenario: &Scenario<()>) -> Result<Runner, Self::Error> {
|
|
// 1. Launch nodes using scenario.topology()
|
|
// 2. Wait for readiness (e.g., consensus info endpoint responds)
|
|
// 3. Build NodeClients for validators/executors
|
|
// 4. Spawn a block feed for expectations (optional but recommended)
|
|
// 5. Create NodeControlHandle if you support restarts (optional)
|
|
// 6. Return a Runner wrapping RunContext + CleanupGuard
|
|
|
|
tracing::info!("deploying scenario with MyDeployer");
|
|
|
|
let topology: Option<Topology> = None; // Some(topology) if you spawned one
|
|
let node_clients = NodeClients::default(); // Or NodeClients::from_topology(...)
|
|
|
|
let client = node_clients
|
|
.any_client()
|
|
.ok_or("no api clients available")?
|
|
.clone();
|
|
let (block_feed, block_feed_guard) = spawn_block_feed(client).await?;
|
|
|
|
let telemetry = Metrics::empty(); // or Metrics::from_prometheus(...)
|
|
let node_control = None; // or Some(Arc<dyn NodeControlHandle>)
|
|
|
|
let context = RunContext::new(
|
|
scenario.topology().clone(),
|
|
topology,
|
|
node_clients,
|
|
scenario.duration(),
|
|
telemetry,
|
|
block_feed,
|
|
node_control,
|
|
);
|
|
|
|
// If you also have other resources to clean up (containers/pods/etc),
|
|
// wrap them in your own CleanupGuard implementation and call
|
|
// CleanupGuard::cleanup(Box::new(block_feed_guard)) inside it.
|
|
Ok(Runner::new(context, Some(Box::new(block_feed_guard))))
|
|
}
|
|
}</code></pre>
|
|
<p><strong>Key points:</strong></p>
|
|
<ul>
|
|
<li><code>deploy()</code> must return a fully prepared <code>Runner</code></li>
|
|
<li>Block until nodes are ready before returning (avoid false negatives)</li>
|
|
<li>Use a <code>CleanupGuard</code> to tear down resources on failure (and on <code>RunHandle</code> drop)</li>
|
|
<li>If you want chaos workloads, also provide a <code>NodeControlHandle</code> via <code>RunContext</code></li>
|
|
</ul>
|
|
<h2 id="adding-topology-helpers"><a class="header" href="#adding-topology-helpers">Adding Topology Helpers</a></h2>
|
|
<p><strong>Steps:</strong></p>
|
|
<ol>
|
|
<li>Extend <code>testing_framework_core::topology::config::TopologyBuilder</code> with new layouts</li>
|
|
<li>Keep defaults safe: ensure at least one participant, clamp dispersal factors</li>
|
|
<li>Consider adding configuration presets for specialized parameters</li>
|
|
</ol>
|
|
<p><strong>Example:</strong></p>
|
|
<pre><code class="language-rust ignore">use testing_framework_core::topology::{
|
|
config::TopologyBuilder,
|
|
configs::network::Libp2pNetworkLayout,
|
|
};
|
|
|
|
pub trait TopologyBuilderExt {
|
|
fn network_full(self) -> Self;
|
|
}
|
|
|
|
impl TopologyBuilderExt for TopologyBuilder {
|
|
fn network_full(self) -> Self {
|
|
self.with_network_layout(Libp2pNetworkLayout::Full)
|
|
}
|
|
}</code></pre>
|
|
<p><strong>Key points:</strong></p>
|
|
<ul>
|
|
<li>Maintain method chaining (return <code>&mut Self</code>)</li>
|
|
<li>Validate inputs: clamp factors, enforce minimums</li>
|
|
<li>Document assumptions (e.g., "requires at least 4 nodes")</li>
|
|
</ul>
|
|
<h2 id="adding-a-dsl-helper"><a class="header" href="#adding-a-dsl-helper">Adding a DSL Helper</a></h2>
|
|
<p>To expose your custom workload through the high-level DSL, add a trait extension:</p>
|
|
<pre><code class="language-rust ignore">use async_trait::async_trait;
|
|
use testing_framework_core::scenario::{DynError, RunContext, ScenarioBuilder, Workload};
|
|
|
|
#[derive(Default)]
|
|
pub struct MyWorkloadBuilder {
|
|
target_rate: u64,
|
|
some_option: bool,
|
|
}
|
|
|
|
impl MyWorkloadBuilder {
|
|
pub const fn target_rate(mut self, target_rate: u64) -> Self {
|
|
self.target_rate = target_rate;
|
|
self
|
|
}
|
|
|
|
pub const fn some_option(mut self, some_option: bool) -> Self {
|
|
self.some_option = some_option;
|
|
self
|
|
}
|
|
|
|
pub const fn build(self) -> MyWorkload {
|
|
MyWorkload {
|
|
target_rate: self.target_rate,
|
|
some_option: self.some_option,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct MyWorkload {
|
|
target_rate: u64,
|
|
some_option: bool,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl Workload for MyWorkload {
|
|
fn name(&self) -> &str {
|
|
"my_workload"
|
|
}
|
|
|
|
async fn start(&self, _ctx: &RunContext) -> Result<(), DynError> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub trait MyWorkloadDsl {
|
|
fn my_workload_with(
|
|
self,
|
|
f: impl FnOnce(MyWorkloadBuilder) -> MyWorkloadBuilder,
|
|
) -> Self;
|
|
}
|
|
|
|
impl MyWorkloadDsl for ScenarioBuilder {
|
|
fn my_workload_with(
|
|
self,
|
|
f: impl FnOnce(MyWorkloadBuilder) -> MyWorkloadBuilder,
|
|
) -> Self {
|
|
let builder = f(MyWorkloadBuilder::default());
|
|
self.with_workload(builder.build())
|
|
}
|
|
}</code></pre>
|
|
<p>Users can then call:</p>
|
|
<pre><code class="language-rust ignore">ScenarioBuilder::topology_with(|t| t.network_star().validators(1).executors(1))
|
|
.my_workload_with(|w| {
|
|
w.target_rate(10)
|
|
.some_option(true)
|
|
})
|
|
.build()</code></pre>
|
|
<h2 id="see-also"><a class="header" href="#see-also">See Also</a></h2>
|
|
<ul>
|
|
<li><a href="api-levels.html">API Levels: Builder DSL vs. Direct</a> - Understanding the two API levels</li>
|
|
<li><a href="custom-workload-example.html">Custom Workload Example</a> - Complete runnable example</li>
|
|
<li><a href="internal-crate-reference.html">Internal Crate Reference</a> - Where to add new code</li>
|
|
</ul>
|
|
|
|
</main>
|
|
|
|
<nav class="nav-wrapper" aria-label="Page navigation">
|
|
<!-- Mobile navigation buttons -->
|
|
<a rel="prev" href="api-levels.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
<a rel="next prefetch" href="custom-workload-example.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
|
|
<div style="clear: both"></div>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
|
|
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
|
<a rel="prev" href="api-levels.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
<a rel="next prefetch" href="custom-workload-example.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
window.playground_copyable = true;
|
|
</script>
|
|
|
|
|
|
<script src="elasticlunr.min.js"></script>
|
|
<script src="mark.min.js"></script>
|
|
<script src="searcher.js"></script>
|
|
|
|
<script src="clipboard.min.js"></script>
|
|
<script src="highlight.js"></script>
|
|
<script src="book.js"></script>
|
|
|
|
<!-- Custom JS scripts -->
|
|
<script src="theme/mermaid-init.js"></script>
|
|
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|