Fracture
β οΈ PROJECT IS IN ALPHA - Fracture is in early development (v0.1.1). The core concepts work, but there are likely edge cases and bugs we haven't found yet. Please report any issues you encounter! The irony is not lost on us that a chaos testing tool needs help finding its own bugs. π
Deterministic chaos testing for async Rust. Drop-in for Tokio.
Fracture is a testing framework that helps you find bugs in async code by simulating failures, network issues, and race conditionsβall deterministically and reproducibly. Note that Fracture is only a drop-in replacement for Tokio and does not work with any other async runtime.
The Problem
Most async Rust code looks fine in tests but breaks in production:
async
Your tests pass because they assume the happy path. Production doesn't.
The Solution
Fracture runs your async code in a simulated environment with deterministic chaos injection:
async
Same seed = same failures = reproducible bugs.
Features
- β Deterministic - Control randomness with seeds, reproduce bugs every time
- β Fast - Pure in-memory simulation, no real network/filesystem
- β Chaos Injection - Network failures, delays, partitions, timeouts, task aborts
- β
Drop-in Testing - Works like
#[tokio::test]but with superpowers - β Async Primitives - Tasks, channels, timers, TCP, select!, timeouts
- β Scenario Builder - Script complex failure sequences (partitions, delays, healing)
Installation
β οΈ Alpha warning: API may change between minor versions until 1.0.0
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
Basic Test
use *;
async
Running Applications with #[fracture::main]
Use #[fracture::main] as a drop-in replacement for #[tokio::main]:
use *;
async
How it works:
- With
simulationfeature enabled: Runs using Fracture's deterministic runtime (for development/testing with chaos injection) - Without
simulationfeature: Falls back to the real Tokio runtime (for production)
This lets you develop and test with Fracture's chaos testing capabilities, then deploy to production with zero code changes by simply disabling the simulation feature.
Example Cargo.toml setup:
[]
# Production: Uses real Tokio runtime
= "0.1"
[]
# Testing: Uses simulation runtime with chaos
= { = "0.1", = ["simulation"] }
With this setup, cargo run uses the real Tokio runtime, while cargo test uses Fracture's simulation.
With Chaos Injection
use *;
use chaos;
async
Network Partition Scenarios
use ;
async
Reproducing Bugs
When a test fails, Fracture shows you the seed:
Run with FRACTURE_SEED=17135321411058301739 to reproduce.
Set the environment variable to get the exact same failure:
FRACTURE_SEED=17135321411058301739
Testing External Libraries (reqwest, sqlx, aws-sdk)
By default, Fracture simulates your logic. External libraries that depend on the real tokio runtime (like database drivers or HTTP clients) will continue to use the real network and OS threads, ignoring your chaos settings.
To simulate chaos in external libraries, you must "patch" Tokio.
We provide a Shim Crate strategy that tricks the entire dependency tree into using Fracture instead of Tokio.
- The Setup
In your Cargo.toml, add a patch directive to redirect tokio to the shim included in this repository:
[patch.crates-io]
β οΈ This forces every library in your tree to use Fracture as its runtime
tokio = { git = "https://github.com/ZA1815/fracture", path = "tokio-shim" }
Alternatively, you can create a .cargo/config.toml file with the same content, this will apply the patch globally to your project without modifying Cargo.toml.
Make sure that for both of these, you delete the patch section before releasing to production.
2. The Rules
When patching is active:
Do NOT enable the tokio feature in fracture. Your Cargo.toml dependencies should look like this:
[dev-dependencies]
Only enable simulation features, do not depend on the real tokio
fracture = { version = "0.1", features = ["simulation"] } Run tests normally: cargo test
Revert for production: Remove the [patch] section when building your actual application release.
Why do this?
Time Travel: fracture::time::sleep(Duration::from_secs(3600)) will instantly advance time for reqwest timeouts.
Network Chaos: You can inject packet loss into sqlx database connections.
Determinism: The entire stack becomes deterministic, including 3rd party driver behavior.
## Use Cases
### Web Backends & APIs
Test your HTTP handlers under real-world conditions:
```rust
#[fracture::test]
async fn test_api_with_database_timeouts() {
chaos::inject(ChaosOperation::TcpRead, 0.2); // 20% DB read failures
let response = handle_get_user(user_id).await;
// Does your code return a proper error? Retry? Use a fallback?
assert!(response.is_ok());
}
Distributed Systems
Test consensus algorithms, replication, leader election:
async
Background Job Processors
Test task queues with failures:
async
Real-Time Systems
Test WebSocket servers, event streams, subscriptions:
async
Available Chaos Operations
Fracture can inject failures into:
- Tasks:
TaskSpawn,TaskAbort,TaskPanic,TaskDeadlock,TaskStarvation - Channels:
MpscSend,MpscRecv,OneshotSend,OneshotRecv - Network:
TcpConnect,TcpAccept,TcpRead,TcpWrite - Time:
SleepShort,SleepLong,TimeoutEarly,TimeoutLate - Threading:
SpawnBlocking,ThreadPoolExhaustion
Set chaos rates from 0.0 (never) to 1.0 (always):
inject; // 50% failure rate
How It Works
- Simulation Runtime - Fracture provides a complete async runtime that runs entirely in-memory
- Deterministic Scheduling - Task execution order is controlled by a seeded RNG
- Chaos Injection - At key points (sends, receives, I/O), Fracture can inject failures
- Time Control - Virtual time advances deterministically, no real sleeps
- Reproducibility - Same seed β same task order β same failures β same bugs
This is inspired by FoundationDB's approach to testing: run thousands of simulated scenarios to find rare edge cases.
Testing Philosophy
Traditional approach:
async
Fracture approach:
async
Fracture forces you to write resilient code from the start.
API Overview
Main Entry Point
// Basic async main (switches between Fracture/Tokio)
// Optional duration parameter (when using simulation)
async
Testing
// Basic test
// Run for 10 simulated seconds
async
Async Primitives
// Tasks
let handle = spawn;
handle.await?;
handle.abort;
// Channels
let = unbounded;
let = channel;
// Time
sleep.await;
timeout.await?;
// Network (simulated)
let listener = bind.await?;
let = listener.accept.await?;
// Select
select!
Chaos Control
// Inject chaos
inject;
// Clear chaos
clear;
// Scenarios
let scenario = new
.seed
.delay
.partition
.wait
.heal_partition;
spawn;
Examples
Check out the tests/ directory for complete examples:
- demo_success.rs - Resilient message passing with retries
- demo_failure.rs - Non-resilient code that fails under chaos
- simple_test.rs - Basic async primitives
- modules_test.rs - Testing different async modules
Comparison
| Feature | Tokio | Loom | Jepsen | Fracture |
|---|---|---|---|---|
| Async runtime | β | β | β | β |
| Deterministic | β | β | β | β |
| Chaos injection | β | β | β | β |
| Fast (in-memory) | β | β | β | β |
| Network simulation | β | β | β | β |
| Reproducible bugs | β | β | β | β |
- Tokio: Production runtime, no chaos testing
- Loom: Concurrency testing (different problem space)
- Jepsen: Live cluster testing (slow, expensive)
- Fracture: Deterministic chaos testing for async code
Limitations & Alpha Status
β οΈ This is alpha software (v0.1.1). We've tested it extensively, but async runtimes are complex and there are undoubtedly edge cases we haven't hit yet.
Known limitations:
- Only works with Fracture's async primitives (not Tokio/async-std directly)
- Limited chaos operations compared to real-world scenarios
- No file I/O simulation yet
- Performance not optimized for massive scale (1000+ tasks may be slow)
- Some edge cases in the runtime may cause panics or incorrect behavior
We NEED your bug reports!
If you find issues (crashes, incorrect behavior, missing features), please:
- Open an issue with details
- Include the seed (
FRACTURE_SEED) if the bug is reproducible - Minimal reproduction code is incredibly helpful
The more people use this in real scenarios, the more robust it becomes. Help us make async Rust more reliable by breaking Fracture first! π¨
Contributing
Found a bug? Want a feature? Open an issue or PR!
Areas we'd love help with:
- More chaos operations
- Performance improvements
- Integration with existing async ecosystems
- Better error messages
- More examples
Roadmap
- File I/O simulation and chaos
- Clock skew injection
- Memory pressure simulation
- Better integration with Tokio/async-std
- Visualization of test execution traces
- Property-based testing integration
- More comprehensive network simulation
Why "Fracture"?
Because we intentionally break your code to make it stronger. Chaos testing finds the fracture points in your system before production does.
License
MIT License. See LICENSE for details.
Acknowledgments
Inspired by:
- FoundationDB's deterministic simulation testing
- Jepsen for pioneering chaos testing
- The Rust async ecosystem (Tokio, async-std, futures)