pub struct TestContext {
pub test_id: String,
pub seed: u64,
pub subsystem: Option<String>,
pub invariant: Option<String>,
}Expand description
Standardized metadata carried through a test for structured logging.
Every test should create a TestContext to ensure consistent, machine-parseable
log fields across all unit, integration, and E2E tests.
§Standard Fields
| Field | Purpose | Example |
|---|---|---|
test_id | Unique identifier for the test run | "cancel_drain_001" |
seed | Deterministic RNG seed for reproducibility | 0xDEAD_BEEF |
subsystem | Runtime subsystem under test | "scheduler", "raptorq" |
invariant | Core invariant being verified | "no_obligation_leaks" |
§Example
use asupersync::test_logging::TestContext;
let ctx = TestContext::new("cancel_drain_001", 0xDEAD_BEEF)
.with_subsystem("cancellation")
.with_invariant("losers_drained");
// Use with TestHarness
let harness = TestHarness::with_context("my_test", ctx);Fields§
§test_id: StringUnique test identifier for log correlation.
seed: u64Deterministic seed for reproducibility.
subsystem: Option<String>Runtime subsystem under test (e.g., “scheduler”, “raptorq”, “obligation”).
invariant: Option<String>Core invariant being verified (e.g., “no_obligation_leaks”, “quiescence”).
Implementations§
Source§impl TestContext
impl TestContext
Sourcepub fn with_subsystem(self, subsystem: &str) -> Self
pub fn with_subsystem(self, subsystem: &str) -> Self
Set the subsystem under test.
Sourcepub fn with_invariant(self, invariant: &str) -> Self
pub fn with_invariant(self, invariant: &str) -> Self
Set the invariant being verified.
Sourcepub fn log_end(&self, passed: bool)
pub fn log_end(&self, passed: bool)
Emit a tracing info event for test completion with all context fields.
Sourcepub fn component_seed(&self, component: &str) -> u64
pub fn component_seed(&self, component: &str) -> u64
Derive a component-specific seed from this context’s root seed.
Sourcepub fn scenario_seed(&self, scenario: &str) -> u64
pub fn scenario_seed(&self, scenario: &str) -> u64
Derive a scenario-specific seed from this context’s root seed.
Sourcepub fn entropy_seed(&self, index: u64) -> u64
pub fn entropy_seed(&self, index: u64) -> u64
Derive an entropy seed for a given iteration index.
Sourcepub fn log_failure(&self, reason: &str)
pub fn log_failure(&self, reason: &str)
Emit a structured error dump with full context for failure triage.
Trait Implementations§
Source§impl Clone for TestContext
impl Clone for TestContext
Source§fn clone(&self) -> TestContext
fn clone(&self) -> TestContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more