fluxion-test-utils
Part of Fluxion - A reactive stream processing library for Rust
Shared test utilities and fixtures used across the fluxion workspace. This crate provides helpers for creating sequenced streams with deterministic timestamps, reusable test data, and common assertions to simplify unit and integration tests.
Features
Sequenced<T>- Counter-based timestamp wrapper for deterministic testing- Test Data Fixtures - Pre-defined
Person,Animal,Planttypes TestDataEnum - Unified enum for diverse test scenarios- Assertion Helpers - Stream testing utilities
- Error Injection -
ErrorInjectingStreamfor testing error handling
Quick Reference
| Utility | Purpose | Use Case |
|---|---|---|
Sequenced<T> |
Counter-based timestamps (u64) | Deterministic ordering in tests |
Sequenced::new(value) |
Auto-assigned sequence number | Quick test values |
Sequenced::with_timestamp(value, ts) |
Explicit timestamp | Control ordering precisely |
test_channel() |
Create test channel | Simplified test setup |
unwrap_stream() |
Extract values from StreamItem | Clean test assertions |
assert_no_element_emitted() |
Verify stream silence | Timeout testing |
Why Sequenced?
Unlike ChronoTimestamped<T> in fluxion-stream-time (which uses real wall-clock time), Sequenced<T> provides:
- ✅ Deterministic behavior: Tests always produce same results
- ✅ No time dependencies: No
tokio::time::sleep()needed - ✅ Explicit control: Set exact timestamps for scenarios
- ✅ Fast execution: No actual delays
- ✅ Reproducible bugs: Same sequence every run
Perfect for unit tests, integration tests, and CI environments.
Usage Examples
Basic Sequencing
use Sequenced;
use ;
async
Using Test Fixtures
use ;
Helper Functions
use ;
use FluxionStream;
async
Error Injection Testing
use ErrorInjectingStream;
use ;
use stream;
async
Sequenced vs ChronoTimestamped
| Feature | Sequenced<T> (this crate) |
ChronoTimestamped<T> (stream-time) |
|---|---|---|
| Timestamp Type | u64 (counter) |
DateTime<Utc> |
| Purpose | Testing, simulation | Production, real time |
| Deterministic | ✅ Always | ❌ Wall-clock dependent |
| Time Operators | ❌ No | ✅ Yes (delay, debounce, etc.) |
| Core Operators | ✅ Yes (all) | ✅ Yes (all) |
| Speed | ⚡ Instant | 🐌 Real delays |
| Dependencies | None | chrono, tokio::time |
| Best For | Unit/integration tests | Production systems |
API Overview
Sequenced
Test Fixtures
Pre-defined test data available in test_data module:
// People
person_alice // Person { id: 1, name: "Alice" }
person_bob // Person { id: 2, name: "Bob" }
person_carol // Person { id: 3, name: "Carol" }
// Animals
animal_cat // Animal { id: 1, species: "Cat" }
animal_dog // Animal { id: 2, species: "Dog" }
// Plants
plant_rose // Plant { id: 1, name: "Rose" }
plant_tulip // Plant { id: 2, name: "Tulip" }
Helper Functions
// Create test channel with FluxionStream
;
// Extract values from stream
pub async ;
// Extract single value
pub async ;
// Assert no emission within timeout
pub async ;
// Assert stream has ended
pub async ;
Running tests
cargo test --package fluxion-test-utils --all-features --all-targets
See Also
- fluxion-stream-time - Time-based operators with
ChronoTimestamped<T> - Fluxion Documentation - Main project documentation
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.