Skip to content

Quick Test Guide - Multi-Tenancy

Quick Test Guide - Multi-Tenancy

Quick reference for running multi-tenancy tests in HeliosDB Nano.

Quick Commands

Terminal window
# Run all multi-tenancy tests (fastest)
cargo test --test multi_tenancy_tests
# Run REPL command tests
cargo test --test repl_tenant_commands
# Run unit tests in tenant module
cargo test --lib tenant::tests
# Run everything related to tenancy
cargo test tenant
# Run with output
cargo test --test multi_tenancy_tests -- --nocapture
# Run specific test
cargo test test_rls_prevents_cross_tenant_select
# Run benchmarks
cargo bench --bench multi_tenancy_bench

Test Categories

🔒 Critical Security Tests (MUST PASS)

Terminal window
# These tests ensure no data leakage between tenants
cargo test test_rls_prevents_cross_tenant_select
cargo test test_rls_prevents_cross_tenant_update
cargo test test_rls_prevents_cross_tenant_delete
cargo test test_cdc_multi_tenant_isolation

📊 Quota Enforcement Tests

Terminal window
cargo test test_connection_limit_enforced
cargo test test_storage_limit_enforced
cargo test test_qps_limit_enforced
cargo test test_quota_window_reset

📝 CDC Tests

Terminal window
cargo test test_cdc_captures_insert
cargo test test_cdc_captures_update
cargo test test_cdc_captures_delete

🔄 Migration Tests

Terminal window
cargo test test_tenant_migration_lifecycle
cargo test test_migration_consistency_verification

Performance Benchmarks

Terminal window
# All benchmarks
cargo bench --bench multi_tenancy_bench
# RLS performance
cargo bench --bench multi_tenancy_bench -- rls
# Quota performance
cargo bench --bench multi_tenancy_bench -- quota
# CDC performance
cargo bench --bench multi_tenancy_bench -- cdc
# Save baseline for comparison
cargo bench --bench multi_tenancy_bench -- --save-baseline main

Coverage Report

Terminal window
# Install tarpaulin (first time only)
cargo install cargo-tarpaulin
# Generate coverage
cargo tarpaulin --out Html --output-dir coverage/ -- tenant
# Open coverage report
open coverage/index.html # macOS
xdg-open coverage/index.html # Linux

Continuous Integration

Terminal window
# CI-style test run (what GitHub Actions runs)
cargo test --test multi_tenancy_tests --test repl_tenant_commands --lib tenant::tests
cargo bench --bench multi_tenancy_bench --no-run

Test Statistics

  • Total Integration Tests: 43
  • Total Unit Tests: 35
  • Total REPL Tests: 50+
  • Total Benchmark Suites: 8
  • Overall Coverage: ~100% for multi-tenancy features

Test Files

FilePurposeTest Count
tests/multi_tenancy_tests.rsIntegration tests43
tests/repl_tenant_commands.rsREPL command parsing50+
src/tenant/mod.rs (tests module)Unit tests35
benches/multi_tenancy_bench.rsPerformance benchmarks8 groups

Expected Test Duration

  • Unit tests: ~0.5 seconds
  • Integration tests: ~2-5 seconds
  • REPL tests: ~1 second
  • Benchmarks: ~5-10 minutes (all suites)

Common Issues

Tests Fail with “tenant_manager not found”

This usually means the EmbeddedDatabase hasn’t been updated to include the tenant_manager field. Check that src/lib.rs exports the tenant module.

Benchmarks Take Too Long

Run specific benchmark groups:

Terminal window
cargo bench --bench multi_tenancy_bench -- rls --quick

Coverage Tool Errors

Ensure you’re using a compatible Rust toolchain:

Terminal window
rustup component add llvm-tools-preview

Next Steps

After running tests:

  1. Check test output for failures
  2. Run benchmarks to establish baseline
  3. Generate coverage report
  4. Review coverage gaps
  5. Add tests for any uncovered scenarios

Pre-Commit Checklist

Before committing changes:

Terminal window
# Format code
cargo fmt
# Run linter
cargo clippy -- -D warnings
# Run tests
cargo test tenant
# Run benchmarks (no-run to save time)
cargo bench --bench multi_tenancy_bench --no-run

Resources

  • Full coverage report: docs/testing/MULTI_TENANCY_TEST_COVERAGE.md
  • Test source: tests/multi_tenancy_tests.rs
  • Benchmarks: benches/multi_tenancy_bench.rs

Quick Tip: Use cargo test tenant -- --test-threads=1 to run tests serially if you encounter race conditions.