MoosicBox Simulation Testing Harness
Comprehensive simulation testing framework for deterministic testing and validation.
Overview
The MoosicBox Simulation Testing Harness provides:
- Simulation Orchestration: Multi-threaded simulation execution and management
- Host/Client Testing: Network simulation with host and client actors
- Deterministic Testing: Reproducible test runs with controlled randomness
- TUI Interface: Optional text-based user interface for simulation monitoring
- Parallel Execution: Configurable parallel simulation runs
- Event System: Simulation lifecycle event hooks and callbacks
Features
Simulation Management
- Multi-Run Support: Execute multiple simulation runs with parallel execution
- Cancellation Support: Graceful simulation cancellation and cleanup
- Thread Management: Worker thread allocation and management
- Progress Tracking: Real-time simulation progress monitoring
Testing Framework
- Host Simulation: Server-side simulation with async action support
- Client Simulation: Client-side simulation and interaction testing
- Result Aggregation: Simulation result collection and analysis
- Network Bouncing: Planned: Host restart and failover simulation
User Interface
- TUI Mode: Optional terminal-based monitoring interface
- Logging Integration: Comprehensive logging with environment logger
- Progress Display: Real-time simulation status and progress
- Error Reporting: Detailed error reporting and stack traces
Configuration
- Environment Variables: Runtime configuration via environment variables
- Bootstrap System: Configurable simulation initialization
- Properties: Custom simulation properties and metadata
- Lifecycle Hooks: Before/after simulation event handlers
Installation
Add this to your Cargo.toml:
[]
= { = "../simvar/harness" }
Usage
Basic Simulation
use ;
use Duration;
;
// Run simulation
let results = run_simulation?;
// Analyze results
for result in results
Advanced Configuration
use ;
use Duration;
;
Host and Client Actors
// Host actor (server simulation)
sim.host;
// Client actor (client simulation)
sim.client;
Note: The bounce method is currently a placeholder and does not restart hosts. Full host bouncing functionality is planned for a future release.
Environment Configuration
Environment Variables
SIMULATOR_RUNS: Number of simulation runs (default: 1)SIMULATOR_MAX_PARALLEL: Maximum parallel runs (default: CPU cores)SIMULATOR_DURATION: Simulation duration with unit suffix (e.g., "10s", "5000ms", "1000µs", "1000ns"; default: unlimited)SIMULATOR_SEED: Fixed seed for deterministic runsSIMULATOR_EPOCH_OFFSET: Fixed simulated epoch offset override (time feature)SIMULATOR_EPOCH_MIN/SIMULATOR_EPOCH_MAX: Inclusive bounded random epoch offset (time feature)SIMULATOR_EPOCH_RANGE_PROFILE: Epoch profilelow|wide|full(time feature)NO_TUI: Disable TUI interface when set at compile timeRUST_LOG: Log level configuration (e.g., "debug", "info", "warn")
When a run fails, the harness prints a copy/paste rerun command that includes both
SIMULATOR_SEED and the failed run's concrete SIMULATOR_EPOCH_OFFSET so replay is exact.
Example Configuration
# Run 10 simulations with 4 parallel workers
# Disable TUI interface (set before compilation)
Features
The package supports the following features:
Default Features
- pretty_env_logger: Environment-based logging configuration
- tui: Terminal user interface for simulation monitoring
TUI Interface
When built with the tui feature (enabled by default), provides:
- Real-time simulation progress
- Run status and results
- Error display and debugging
- Interactive simulation monitoring
Disable by excluding default features, or by setting NO_TUI at compile time.
Optional Features
- async: Async simulation support (via switchy)
- database: Database connection simulation (via switchy)
- fs: File system simulation (via switchy)
- fs-simulator-real-fs: Enable real filesystem seeding helpers for simulator setup (via switchy)
- http: HTTP simulation (via switchy)
- mdns: mDNS simulation (via switchy)
- random: Randomness simulation controls (via switchy)
- tcp: TCP network simulation (via switchy)
- telemetry: Telemetry support (via switchy)
- time: Time manipulation for simulation (via switchy)
- upnp: UPnP simulation (via switchy)
- web-server: Web server simulation support
Logging Integration
- Environment-based log level configuration
- Structured logging with simulation context
- Error tracking and stack traces
- Performance metrics
Error Handling
Comprehensive error types:
- Step Errors: Simulation step execution failures
- Join Errors: Thread joining and coordination failures
- IO Errors: File system and network operation failures
Dependencies
- switchy: Async runtime and simulation utilities
- simvar_utils: Simulation utilities and helpers
- color-backtrace: Enhanced error reporting
- ratatui: Optional terminal interface (with
tuifeature) - pretty_env_logger: Optional environment logger integration (default feature)
Integration
This package is designed for:
- Load Testing: High-throughput simulation testing
- Integration Testing: Multi-service interaction testing
- Chaos Engineering: Failure injection and recovery testing
- Performance Testing: Latency and throughput validation