This document describes the testing strategy and how to run tests for the JSON-DB-Sync project.
We follow a pragmatic testing approach:
- Minimal unit tests for pure functions (auth token hashing, validators)
- Comprehensive integration tests for real-world scenarios
- Property-based tests for conflict resolution
- Load tests for concurrent connections
sync-server/tests_integration/
├── integration_tests.rs # Main integration test entry point
├── integration/
│ ├── mod.rs # Module declarations
│ ├── helpers.rs # Test utilities and helpers
│ ├── auth_integration.rs # Authentication flow tests
│ ├── sync_flow_integration.rs # Document sync scenarios
│ ├── conflict_resolution_integration.rs # Conflict handling
│ ├── websocket_integration.rs # WebSocket protocol tests
│ └── concurrent_clients_integration.rs # Load and concurrency tests
├── basic_test.rs # Core integration tests
└── full_sync_test.rs # End-to-end sync scenarios
sync-server/tests/
└── unit_tests.rs # Server-specific unit tests
test/
├── run_integration_tests.sh # Docker-based integration tests
├── run_integration_tests_fast.sh # Fast integration tests with caching
└── run_integration_tests_local.sh # Local integration tests
# Unit tests
cargo test --lib --bins
# Integration tests (local PostgreSQL - fast)
./test/run_integration_tests_local.sh
# Integration tests (Docker - consistent environment)
./test/run_integration_tests_docker.sh
# Manual integration test setup
docker-compose -f docker-compose.test.yml up -d
export RUN_INTEGRATION_TESTS=1
export TEST_DATABASE_URL="postgres://postgres:postgres@localhost:5433/sync_test_db"
cargo test integration -- --test-threads=1# Run all unit tests
cargo test --lib --bins
# Run specific test
cargo test test_token_hashing# Run integration tests with automated setup/teardown (requires local PostgreSQL)
./test/run_integration_tests_local.sh# Run integration tests with Docker (consistent environment, no local PostgreSQL needed)
./test/run_integration_tests_docker.sh# Start PostgreSQL
docker-compose -f docker-compose.test.yml up -d
# Set environment variables
export TEST_DATABASE_URL="postgres://postgres:postgres@localhost:5433/sync_test_db"
export RUN_INTEGRATION_TESTS=1
# Run integration tests
cargo test integration -- --nocapture# Auth tests only
cargo test integration::auth_integration
# Conflict resolution tests
cargo test integration::conflict_resolution
# WebSocket tests
cargo test integration::websocketuse crate::integration::helpers::*;
integration_test!(test_my_scenario, |ctx: TestContext| async move {
// Setup
let user_id = Uuid::new_v4();
let client = ctx.create_test_client(user_id, "demo-token").await;
// Test logic
let doc = TestContext::create_test_document(user_id, "Test Doc");
client.create_document(doc).await.unwrap();
// Assertions
let docs = client.get_all_documents().await.unwrap();
assert_eq!(docs.len(), 1);
});TestContext: Provides server URL, database URL, and utility methodscreate_test_client(): Creates authenticated sync clientcreate_test_document(): Generates test documentsassert_eventually(): Waits for async conditionscreate_authenticated_websocket(): Direct WebSocket connection
Tests run automatically on:
- Push to
mainordevelopbranches - Pull requests to
main
GitHub Actions workflow includes:
- Unit tests
- Integration tests (with PostgreSQL service)
- Docker integration tests
- Linting (rustfmt, clippy)
- Security audit
Load tests are included in concurrent_clients_integration.rs:
- Many concurrent clients test
- Rapid update scenarios
- Server under load conditions
export RUST_LOG=debug
export RUST_BACKTRACE=1
cargo test integration::failing_test -- --nocapture# During Docker tests
docker-compose -f docker-compose.integration.yml logs -f sync-server-test# Connect to test database
docker exec -it sync-workspace_postgres-test_1 psql -U postgres -d sync_test_db
# View test data
\dt # List tables
SELECT * FROM users;
SELECT * FROM documents;If you see "Skipping integration test", set:
export RUN_INTEGRATION_TESTS=1Ensure PostgreSQL is running:
docker-compose -f docker-compose.test.yml psIf ports 5433 or 8081 are in use, modify docker-compose.integration.yml
- ✅ Authentication flows (demo token, custom tokens, auto-registration)
- ✅ Basic sync operations (create, update, delete)
- ✅ Conflict resolution scenarios
- ✅ WebSocket protocol handling
- ✅ Concurrent client scenarios
- ✅ Error handling and recovery
- ✅ Performance under load
- ⬜ Network failure simulation
- ⬜ Database failure recovery
- ⬜ Memory usage under stress