cmd/litestream-test/README.md
A CLI testing harness for Litestream that provides tools for database population, load generation, and replication validation.
litestream-test is a purpose-built tool for testing Litestream's replication functionality across various scenarios. It provides commands for:
go build -o bin/litestream-test ./cmd/litestream-test
Quickly populate a database to a target size with structured test data.
litestream-test populate -db <path> [options]
Options:
-db - Database path (required)-target-size - Target database size (default: "100MB", examples: "1GB", "500MB", "50MB")-row-size - Average row size in bytes (default: 1024)-batch-size - Rows per transaction (default: 1000)-table-count - Number of tables to create (default: 1)-index-ratio - Percentage of columns to index, 0.0-1.0 (default: 0.2)-page-size - SQLite page size in bytes (default: 4096)Examples:
litestream-test populate -db /tmp/test.db -target-size 1GB
litestream-test populate -db /tmp/test.db -target-size 50MB -batch-size 10000
litestream-test populate -db /tmp/test.db -target-size 1.5GB -page-size 4096
Use Cases:
Generate continuous write and read load on a database with configurable patterns.
litestream-test load -db <path> [options]
Options:
-db - Database path (required, must exist)-write-rate - Writes per second (default: 100)-duration - How long to run (default: 1m, examples: "30s", "5m", "2h", "8h")-pattern - Write pattern (default: "constant")
constant - Steady write rateburst - Periodic bursts of activityrandom - Random write intervalswave - Sinusoidal pattern simulating varying load-payload-size - Size of each write in bytes (default: 1024)-read-ratio - Read/write ratio, 0.0-1.0 (default: 0.2)-workers - Number of concurrent workers (default: 1)Examples:
litestream-test load -db /tmp/test.db -write-rate 50 -duration 5m
litestream-test load -db /tmp/test.db -write-rate 100 -duration 2h -pattern wave
litestream-test load -db /tmp/test.db -write-rate 200 -duration 8h -workers 4 -pattern burst
Use Cases:
Shrink a database by deleting data, useful for testing compaction scenarios.
litestream-test shrink -db <path> [options]
Use Cases:
Validate that a replica can be restored and matches the source database.
litestream-test validate [options]
Options:
-source-db - Original database path (required)-replica-url - Replica URL to validate (e.g., "file:///path", "s3://bucket/path")-restored-db - Path for restored database (default: source-db + ".restored")-check-type - Type of validation (default: "quick")
quick - Fast row count comparisonintegrity - SQLite PRAGMA integrity_checkchecksum - Full database checksum comparisonfull - All validation types-ltx-continuity - Check LTX file continuity (default: false)-config - Litestream config file path (alternative to replica-url)Examples:
litestream-test validate -source-db /tmp/test.db -replica-url file:///tmp/replica
litestream-test validate -source-db /tmp/test.db -replica-url s3://bucket/path -check-type full
litestream-test validate -source-db /tmp/test.db -config /tmp/litestream.yml -ltx-continuity
Use Cases:
Show version information.
litestream-test version
litestream-test populate -db /tmp/test.db -target-size 100MB
litestream replicate /tmp/test.db file:///tmp/replica &
LITESTREAM_PID=$!
litestream-test load -db /tmp/test.db -duration 5m -write-rate 50
kill $LITESTREAM_PID
wait
litestream-test validate -source-db /tmp/test.db -replica-url file:///tmp/replica
litestream-test populate -db /tmp/test.db -target-size 100MB
litestream replicate -config litestream.yml &
litestream-test load -db /tmp/test.db \
-duration 8h \
-write-rate 100 \
-pattern wave \
-workers 4
litestream-test populate -db /tmp/test.db \
-target-size 1.5GB \
-page-size 4096 \
-batch-size 10000
litestream replicate /tmp/test.db s3://bucket/path &
litestream-test validate -source-db /tmp/test.db \
-replica-url s3://bucket/path \
-check-type full
The litestream-test tool is used by all scripts in the scripts/ directory. These scripts orchestrate full test scenarios:
scripts/*.sh - Use litestream-test for database operationsscripts/verify-test-setup.sh - Checks that litestream-test is builtscripts/README.md for detailed test scenario documentationgo build -o bin/litestream-test ./cmd/litestream-test
go test ./cmd/litestream-test/...
cmd/litestream-test/ (e.g., mycommand.go)main.go