Testing
MynaDB employs a comprehensive multi-layered testing strategy inspired by industry-leading time series databases like InfluxDB, TimescaleDB, ClickHouse, and QuestDB. This ensures data integrity, query correctness, and performance reliability.
MynaDB includes 200+ tests across unit tests, integration tests, property-based tests, fuzz tests, and performance benchmarks.
Testing Overview
| Test Category | Framework | Coverage | Purpose |
|---|---|---|---|
| Unit Tests | Rust built-in | 146+ tests | Core module functionality |
| Correctness Tests | Rust tests | 50+ edge cases | Query result accuracy |
| Property Tests | proptest | 20+ properties | Invariant verification |
| Fuzz Tests | cargo-fuzz / libfuzzer | 3 targets | Input robustness |
| Benchmarks | Criterion | 50+ benchmarks | Performance regression |
| Integration Tests | Bash scripts | 22 scripts | End-to-end validation |
Unit Tests
Unit tests verify individual module functionality. MynaDB has 146+ unit tests covering core components:
Storage Layer
- Line protocol parsing
- Parquet read/write
- WAL operations
- Data cache
Query Engine
- Time bucket functions
- first_value / last_value
- Fill operations
- Query caching
Background Jobs
- Compaction strategies
- Retention policies
- Metadata management
- File operations
# Run all unit tests
cargo test
# Run tests for a specific module
cargo test --lib cache
cargo test --lib compactor
cargo test --lib wal
cargo test --lib line_protocol
# Run tests with output
cargo test -- --nocapture
Correctness Tests
Correctness tests verify that query results match expected values. These tests cover aggregations, edge cases, and data integrity:
Aggregation Accuracy
Tests verify that SQL aggregations return mathematically correct results:
- SUM - Exact summation of numeric values
- AVG - Mean calculation with floating-point precision
- COUNT - Row counting including NULL handling
- MIN/MAX - Extreme value detection
- DISTINCT - Unique value counting
Edge Cases
| Category | Test Cases |
|---|---|
| Floating Point | Zero values, negative numbers, scientific notation, precision limits, NaN/Infinity handling |
| Integers | Large values (i64 max), negative integers, zero |
| Strings | Empty strings, Unicode, special characters, quotes, escape sequences |
| Timestamps | Epoch boundaries, far future dates, millisecond/nanosecond precision |
| Tags | Many tags (10+), numeric values, hyphens, underscores |
| Queries | Empty results, single row, LIMIT/OFFSET, ORDER BY, GROUP BY with HAVING |
# Run correctness tests
cargo test --test correctness
# Run specific correctness test
cargo test --test correctness test_floating_point_precision
Property-Based Testing
Property-based tests use proptest to generate random inputs and verify invariants hold across all cases.
Parser Properties
proptest! {
// Line protocol roundtrip: parse → serialize → parse = same result
#[test]
fn line_protocol_roundtrip(
measurement in "[a-z]+",
tag_key in "[a-z]+",
tag_value in "[a-z0-9]+",
field_key in "[a-z]+",
field_value in any::<f64>().prop_filter("finite", |v| v.is_finite()),
) {
let line = format!("{},{}={} {}={}",
measurement, tag_key, tag_value, field_key, field_value);
let parsed = parse_line_protocol(&line)?;
// Verify parsed values match inputs
}
// Tag order independence
#[test]
fn tag_order_independent(tags in prop::collection::vec("[a-z]+", 2..5)) {
// Tags in any order should produce equivalent results
}
}
Query Properties
- COUNT equals inserted rows - Insert N rows, COUNT(*) = N
- SUM is commutative - Order of insertion doesn't affect sum
- MIN ≤ AVG ≤ MAX - Aggregate ordering invariant
- Empty result for non-matching filter - Query with impossible predicate returns 0 rows
# Run property tests
cargo test --test property
# Run with more test cases (slower but more thorough)
PROPTEST_CASES=1000 cargo test --test property
Fuzz Testing
Fuzz testing uses cargo-fuzz with libFuzzer to discover edge cases and potential crashes in parsers.
Fuzz Targets
| Target | Description | Inputs Tested |
|---|---|---|
fuzz_line_protocol |
InfluxDB line protocol parser | Malformed lines, special characters, edge cases |
fuzz_time_interval |
Duration string parser (1h, 5m, 30s) | Invalid formats, boundary values, overflow |
fuzz_field_value |
Field value parser (floats, ints, strings, bools) | Type confusion, escape sequences, quotes |
# Install cargo-fuzz (requires nightly)
cargo +nightly install cargo-fuzz
# Run fuzz tests (runs indefinitely, Ctrl+C to stop)
cargo +nightly fuzz run fuzz_line_protocol
# Run for a specific duration
cargo +nightly fuzz run fuzz_line_protocol -- -max_total_time=60
# List all fuzz targets
cargo +nightly fuzz list
Run fuzz tests for extended periods (hours or overnight) to discover rare edge cases. Crashes are automatically saved to fuzz/artifacts/ for reproduction.
Performance Benchmarks
Performance benchmarks use Criterion for statistical analysis and regression detection.
Benchmark Categories
Line Protocol
- Single line parsing
- Batch parsing (100-10000 lines)
- Complex lines (many tags/fields)
- Parallel parsing throughput
- Error path performance
Query Execution
- Simple SELECT queries
- Aggregations (SUM, AVG, COUNT)
- Filter predicates
- GROUP BY operations
- Time range queries
Time Functions
- TimeInterval parsing
- time_bucket calculations
- Fill option parsing
- Boundary conditions
- Large dataset handling
Edge Case Benchmarks
Benchmarks include edge cases to ensure consistent performance across all inputs:
- Numeric extremes - Very large/small floats, scientific notation
- Long strings - Field values with 1000+ characters
- Many fields/tags - Lines with 10+ tags or fields
- Error paths - Malformed input handling overhead
- Empty results - Queries matching no data
- Sparse data - Time series with gaps
# Run all benchmarks
cargo bench
# Run specific benchmark suite
cargo bench --bench line_protocol_bench
cargo bench --bench query_bench
cargo bench --bench time_functions_bench
# Generate HTML report
cargo bench -- --save-baseline main
# Open target/criterion/report/index.html
Benchmark Output
Criterion provides detailed statistical analysis:
line_protocol/parse_single_line
time: [1.2341 µs 1.2456 µs 1.2589 µs]
change: [-2.1234% -0.8765% +0.4321%] (p = 0.19 > 0.05)
No change in performance detected.
line_protocol/batch_1000_lines
time: [1.1234 ms 1.1456 ms 1.1789 ms]
thrpt: [848.23 Klines/s 872.89 Klines/s 890.12 Klines/s]
Integration Tests
Integration tests verify end-to-end functionality using bash scripts that interact with a running MynaDB instance.
Test Scripts
| Script | Category | Description |
|---|---|---|
test_write.sh |
Write Path | Catalog.schema.table structure |
test_schemas.sh |
Schema | Schema and table listing APIs |
test_partitions.sh |
Partition | Partition management |
test_compaction.sh |
Compaction | Basic leveled compaction |
test_compaction_multilevel.sh |
Compaction | Multi-level L0→L1→L2 |
test_auth.sh |
Auth | Basic authentication |
test_mysql.sh |
Protocol | MySQL wire protocol |
test_group_by_time.sh |
Query | Time bucket aggregations |
test_comprehensive.sh |
E2E | Full integration test |
# Run integration tests
cd scripts
# Run individual test
./test_write.sh
./test_compaction.sh
# Run comprehensive test suite
./test_comprehensive.sh
Chaos Testing
Chaos tests simulate failure scenarios to verify data durability and recovery:
- Process crash during write - Verify WAL recovers unflushed data
- Crash during compaction - Verify no data loss or corruption
- Disk full simulation - Graceful error handling
- Concurrent operations - Read during compaction, write during query
# Run chaos tests
./scripts/test_chaos.sh
# Test WAL recovery
./scripts/test_wal_recovery.sh
Running All Tests
# Quick validation (unit + correctness + property tests)
cargo test
# Full test suite
cargo test --all-targets
# Include benchmarks (compile only, don't run)
cargo test --all-targets --benches
# Run benchmarks
cargo bench
# Fuzz testing (requires nightly)
cargo +nightly fuzz run fuzz_line_protocol -- -max_total_time=60
# Integration tests
./scripts/test_comprehensive.sh
Phase A: Data Integrity Tests
Data integrity tests verify that MynaDB correctly handles data throughout its lifecycle: write, flush, compaction, recovery, and query. These tests ensure zero data loss and exact value preservation under all conditions.
Comprehensive coverage of write/read roundtrips, WAL recovery, compaction preservation, and data consistency.
Write/Read Roundtrip Tests (11 tests)
These tests verify that data written to MynaDB can be read back with exact precision:
| Test | Description | Verification |
|---|---|---|
test_roundtrip_basic_float |
Float field values (23.456, 19.876, etc.) | SUM matches expected with <0.001 tolerance |
test_roundtrip_integer_fields |
Integer field values (100i, 250i, 75i) | Exact SUM match |
test_roundtrip_boolean_fields |
Boolean field values (true/false) | Count of true values preserved |
test_roundtrip_string_fields |
String field values with quotes | Row count preserved |
test_roundtrip_mixed_types |
Float + integer + boolean + string in one write | All field types preserved |
test_roundtrip_large_batch |
1000 rows in single write | COUNT=1000, SUM matches |
test_roundtrip_special_characters |
Tags with /api/v1, hyphens, underscores | All rows queryable |
test_roundtrip_many_tags |
7 tags per data point | All tags preserved |
test_roundtrip_many_fields |
10 fields per data point | All field values preserved |
test_roundtrip_precision_floats |
Scientific notation (1e-15, 1e15) | Extreme values preserved |
test_roundtrip_timestamp_preservation |
Explicit nanosecond timestamps | Time ordering preserved |
WAL Recovery Tests (4 tests)
Write-Ahead Log (WAL) recovery tests verify that unflushed data is never lost after a crash. These tests simulate crashes and verify complete data recovery.
| Test | Scenario | Verification |
|---|---|---|
test_wal_recovery_basic |
Write 3 rows → crash → restart | All 3 rows recovered with exact values |
test_wal_recovery_multiple_writes |
5 separate write operations → crash | All 5 writes recovered |
test_wal_recovery_after_partial_flush |
Flush batch 1 → write batch 2 → crash | Both flushed and unflushed data present |
test_wal_recovery_large_batch |
Write 500 rows → crash → restart | COUNT=500, SUM matches exactly |
Compaction Preservation Tests (5 tests)
Compaction tests verify that the LSM-tree compaction process never loses or corrupts data. Data is written across multiple flushes, then compacted, with verification before and after.
| Test | Scenario | Verification |
|---|---|---|
test_compaction_preserves_count |
4 batches × 100 rows → compact | COUNT=400 before and after |
test_compaction_preserves_values |
Known values across 3 batches | SUM, MIN, MAX unchanged |
test_compaction_preserves_all_field_types |
Float, int, bool, string fields | All types preserved after compaction |
test_compaction_preserves_tags |
3 hosts × 3 regions × 3 batches | Tag-filtered queries return same results |
test_compaction_multilevel |
10 batches triggering L0→L1→L2 | COUNT=500, SUM unchanged through all levels |
Running Data Integrity Tests
# Run all data integrity tests (requires sequential execution)
cargo test --test data_integrity -- --test-threads=1
# Run only roundtrip tests
cargo test --test data_integrity test_roundtrip -- --test-threads=1
# Run only WAL recovery tests
cargo test --test data_integrity test_wal -- --test-threads=1
# Run only compaction tests
cargo test --test data_integrity test_compaction -- --test-threads=1
# Run with verbose output
cargo test --test data_integrity -- --test-threads=1 --nocapture
Data integrity tests must run with --test-threads=1 because each test starts its own MynaDB server instance. Parallel execution would cause port conflicts.
Phase B: Concurrency & Stress Tests
Concurrency tests verify that MynaDB maintains data consistency under concurrent load. These tests simulate real-world scenarios with multiple writers, readers, and background operations happening simultaneously.
Multi-threaded writes, read consistency during operations, and stress testing at 8000+ writes/second.
Concurrent Write Tests (4 tests)
These tests verify that no writes are lost when multiple threads write simultaneously:
| Test | Scenario | Verification |
|---|---|---|
test_concurrent_writes_single_table |
4 threads × 100 writes to same table | COUNT=400, no errors |
test_concurrent_writes_multiple_tables |
4 threads × 50 writes to different tables | Each table has exactly 50 rows |
test_concurrent_writes_no_duplicates |
4 threads with unique IDs | COUNT(DISTINCT id) = total writes |
test_concurrent_writes_with_flush |
3 writers + 1 flusher running concurrently | No writes lost during flush |
Read Consistency Tests (3 tests)
These tests verify that reads never see inconsistent or corrupted data during background operations:
| Test | Scenario | Verification |
|---|---|---|
test_read_during_write |
Continuous reads while 100 rows written | Count never decreases below initial |
test_read_during_compaction |
Queries during L0→L1 compaction | Count stays constant throughout |
test_query_isolation |
Aggregation queries during batch writes | No query failures or corrupted results |
Stress Tests (3 tests)
These tests push MynaDB to its limits to verify behavior under extreme load:
| Test | Scenario | Performance |
|---|---|---|
test_stress_high_throughput_writes |
8 threads × 250 writes | 8000+ writes/second |
test_stress_mixed_read_write |
2 writers + 4 readers | No inconsistent reads |
test_stress_burst_writes |
5 bursts of 200 writes each | All bursts preserved |
Data Consistency Tests (3 tests)
These tests verify aggregate consistency during concurrent modifications:
| Test | Scenario | Verification |
|---|---|---|
test_consistency_aggregation_during_writes |
SUM queries during inserts | Sum never decreases |
test_consistency_count_monotonic |
COUNT queries during inserts | Count is monotonically non-decreasing |
test_no_data_loss_under_load |
6 threads + periodic flushes | Every written ID present in final result |
Running Concurrency Tests
# Run all concurrency tests (requires sequential execution)
cargo test --test concurrency -- --test-threads=1
# Run only concurrent write tests
cargo test --test concurrency test_concurrent -- --test-threads=1
# Run only stress tests
cargo test --test concurrency test_stress -- --test-threads=1
# Run only consistency tests
cargo test --test concurrency test_consistency -- --test-threads=1
# Run with verbose output to see throughput metrics
cargo test --test concurrency test_stress_high_throughput -- --test-threads=1 --nocapture
Quick Reference: Running Tests
# ═══════════════════════════════════════════════════════════════════
# COMPLETE TEST SUITE
# ═══════════════════════════════════════════════════════════════════
# Run all unit tests (fast, ~10 seconds)
cargo test
# Run all integration tests
cargo test --test data_integrity -- --test-threads=1
cargo test --test concurrency -- --test-threads=1
cargo test --test correctness -- --test-threads=1
cargo test --test property
# ═══════════════════════════════════════════════════════════════════
# PHASE A: DATA INTEGRITY
# ═══════════════════════════════════════════════════════════════════
# All data integrity tests (29 tests, ~4 minutes)
cargo test --test data_integrity -- --test-threads=1
# Roundtrip tests only (11 tests)
cargo test --test data_integrity test_roundtrip -- --test-threads=1
# WAL recovery tests only (4 tests)
cargo test --test data_integrity test_wal -- --test-threads=1
# Compaction tests only (5 tests)
cargo test --test data_integrity test_compaction -- --test-threads=1
# ═══════════════════════════════════════════════════════════════════
# PHASE B: CONCURRENCY & STRESS
# ═══════════════════════════════════════════════════════════════════
# All concurrency tests (13 tests, ~2 minutes)
cargo test --test concurrency -- --test-threads=1
# Concurrent write tests only
cargo test --test concurrency test_concurrent -- --test-threads=1
# Stress tests only (includes throughput metrics)
cargo test --test concurrency test_stress -- --test-threads=1 --nocapture
# ═══════════════════════════════════════════════════════════════════
# PERFORMANCE BENCHMARKS
# ═══════════════════════════════════════════════════════════════════
# Run all benchmarks
cargo bench
# Run specific benchmark
cargo bench --bench line_protocol_bench
# ═══════════════════════════════════════════════════════════════════
# FUZZ TESTING (requires nightly)
# ═══════════════════════════════════════════════════════════════════
# Run for 60 seconds
cargo +nightly fuzz run fuzz_line_protocol -- -max_total_time=60
CI/CD Integration
All tests run automatically in CI/CD pipelines:
| Stage | Tests | When |
|---|---|---|
| Pre-commit | Unit tests, correctness tests | Every commit |
| Pull Request | All tests + benchmarks (no regression check) | PR creation/update |
| Merge to main | Full suite + benchmark baseline update | Merge |
| Nightly | Extended fuzz testing, stress tests | Daily |