Deterministic Simulation Testing for containerised services.
Write Lua scripts to define, control, and verify chaos experiments on Docker containers with reproducible fault injection.
Workload generation, walkable fault trees and benefit of the LuaJIT std lib.
From crates.io:
cargo install dstest
# Run a script file
dstest < examples/oracle.lua
# Or use REPL mode: type your script interactively, press Ctrl+D to execute
dstestOr build from source:
git clone https://github.com/bxrne/dstest
cd dstest
cargo build --release# Run a script file
cat examples/oracle.lua | cargo run
# Or use REPL mode: type your script and press Ctrl+D to run it
cargo rundstest lets you write Lua scripts that define test subjects (Docker containers), inject faults (pause, kill, resource deprivation, proxied network impairments), and verify service resilience: including virtual clocks for time-dependent logic, seeded workload randomness, depends for multi-service startup ordering, and sustained workload generation from OpenAPI specs.
Important
Deterministic Execution & Workloads
While fault selection and schedule generation are seed-deterministic, standard container execution under default runtimes (runc) is subject to OS process/thread scheduling variance and wall-clock timing jitter. To make container execution and workload timing fully deterministic across runs, subjects must be configured with the dtrun OCI runtime:
local s = dstest.setup(cfg, {
image = "my-service:latest",
runtime = "dtrun", -- Enables deterministic execution via dtrun
ports = { 8080 },
})openapi.lua- Drive sustained HTTP workload from an OpenAPI spec fileoracle.lua- Fault injection with oracle predicates and invariantslink.lua- Proxied network faults: latency, loss, partitions between subjectspartition.lua- Directional link partitions and latency/loss measured through a proxyclock.lua- Virtual clock control: freeze, advance, offset (manual clock)tcp.lua- Raw TCP protocol exchange overdstest.net.tcpstorage.lua- Virtual disk faults: corrupt, snapshot, restore, I/O errorsorchestrate.lua- Full fault-schedule orchestration withrun_stepsand oraclespg.lua- PostgreSQL: connect, create table, insert, query, close
See DOCS.md for the full Lua API reference.
This repo includes an AI skill (SKILL.md) that teaches assistants how to work with dstest.
To use with your agent:
# Claude Code / Opencode
cp SKILL.md ~/.config/opencode/skills/dstest/SKILL.md
# Other agents (e.g., ~/.agents/skills/)
mkdir -p ~/.agents/skills/dstest
cp SKILL.md ~/.agents/skills/dstest/SKILL.mdThen instruct your assistant to "use the dstest skill" when writing or debugging chaos experiments.
Four examples need a real Linux Docker environment that a macOS + podman-machine host cannot provide:
| Example | Why it fails on podman-machine (macOS) |
|---|---|
httpbin.lua |
The link proxy's bridge IP (10.88.x.x) is unreachable from the host process |
link.lua |
Same bridge-reachability requirement |
partition.lua |
Same bridge-reachability requirement |
storage.lua |
Needs root + device-mapper (losetup, dmsetup, mkfs.ext4, mount) and the dm-flakey kernel module |
The harness host process must be able to dial the Docker bridge IP that the link
proxy binds; from inside the macOS podman-machine VM the sandbox bridge is not
routable, and the VM kernel does not expose dm-flakey. These are environment
limitations, not example bugs.
These four examples are not exercised by the automated checks on this host and no
in-repo workaround exists: running them requires a real Linux Docker host where
the bridge IP is reachable from the dstest process and root/device-mapper with
dm-flakey is available. They are documented for completeness and are expected
to fail here.
- A Docker-compatible daemon reachable over
DOCKER_HOST(Docker or Podman withDOCKER_HOSTpointed at the Podman socket;dockermay be aliased topodman) - Rust 1.85+ (uses 2024 edition)
- Zig:
build.rscross-compiles the virtual-clock shim (shim/clock.c) to a Linux x86-64 ELF pinned to the glibc 2.17 baseline withzig cc, so it loads into any glibc-based subject. Zig is required on every build platform, including Linux and CI. Install vianix profile install nixpkgs#zigor your package manager.
MIT