cmd/litestream-test/S3-RETENTION-TESTING.md
This document describes the comprehensive S3 LTX file retention testing scripts created to validate that old LTX files are properly cleaned up after their retention period expires. These tests use the local Python S3 mock server for isolated, repeatable testing.
test-s3-retention-small-db.shPurpose: Test S3 LTX retention cleanup with small databases
Features:
Usage:
./cmd/litestream-test/scripts/test-s3-retention-small-db.sh
Duration: ~8 minutes
test-s3-retention-large-db.shPurpose: Test S3 LTX retention cleanup with large databases crossing the 1GB SQLite lock page boundary
Features:
Usage:
./cmd/litestream-test/scripts/test-s3-retention-large-db.sh
Duration: ~15-20 minutes
test-s3-retention-comprehensive.shPurpose: Comprehensive test runner and analysis tool
Features:
Usage:
# Run all tests
./cmd/litestream-test/scripts/test-s3-retention-comprehensive.sh
# Run only small database test
./cmd/litestream-test/scripts/test-s3-retention-comprehensive.sh --small-only
# Run only large database test
./cmd/litestream-test/scripts/test-s3-retention-comprehensive.sh --large-only
# Keep test files after completion
./cmd/litestream-test/scripts/test-s3-retention-comprehensive.sh --no-cleanup
Duration: ~25-30 minutes for full suite
SQLite reserves a special lock page at exactly 1GB (offset 0x40000000) that cannot contain data. This creates a critical edge case that Litestream must handle correctly.
| Page Size | Lock Page # | Test Coverage |
|---|---|---|
| 4KB | 262145 | ✅ Tested |
| 8KB | 131073 | 🔄 Possible |
| 16KB | 65537 | 🔄 Possible |
| 32KB | 32769 | 🔄 Possible |
The tests use the existing ./etc/s3_mock.py script which:
LITESTREAM_S3_ACCESS_KEY_ID="lite"
LITESTREAM_S3_SECRET_ACCESS_KEY="stream"
LITESTREAM_S3_BUCKET="test{timestamp}"
LITESTREAM_S3_ENDPOINT="http://127.0.0.1:5000"
LITESTREAM_S3_FORCE_PATH_STYLE="true"
The scripts monitor logs for these cleanup indicators:
pip3 install moto boto3
The scripts automatically:
/tmp/small-retention-test.log - Small database replication log/tmp/large-retention-test.log - Large database replication log/tmp/small-retention-config.yml - Small database config/tmp/large-retention-config.yml - Large database config/tmp/small-retention-test.db - Small test database/tmp/large-retention-test.db - Large test database/tmp/small-retention-restored.db - Restored small database/tmp/large-retention-restored.db - Restored large databaseEach test generates:
These tests complement the existing test infrastructure:
test-s3-retention-cleanup.sh: Original retention test (more basic)test-754-s3-scenarios.sh: Issue #754 specific testinglitestream-test CLI for data generationetc/s3_mock.py for S3 simulationlitestream-test populate/load/validate commandspip3 install moto boto3
go build -o bin/litestream ./cmd/litestream
go build -o bin/litestream-test ./cmd/litestream-test
For more verbose output:
# Enable debug logging
export LITESTREAM_DEBUG=1
# Run with debug
./cmd/litestream-test/scripts/test-s3-retention-comprehensive.sh
These retention testing scripts provide comprehensive validation of Litestream's S3 LTX file cleanup behavior across different database sizes and scenarios. They specifically address:
The scripts are designed to run reliably in isolation while providing detailed insights into Litestream's retention cleanup behavior.