This directory contains comprehensive integration and data consistency tests for the Lynx URL shortener.
Comprehensive integration test suite covering all API endpoints and functionality:
Test Coverage (20 tests):
- Health check endpoint
- Auth mode endpoint
- URL creation with custom code
- URL creation with auto-generated code
- Get URL details
- Redirect functionality
- Click count verification
- List URLs endpoint
- URL deactivation
- Deactivated URL returns proper error code
- URL reactivation
- Reactivated URL works correctly
- Rapid URL creation (50 URLs stress test)
- Concurrent redirects to same URL
- URLs with special characters
- Pagination functionality
- Non-existent URL handling
- Duplicate code rejection
- Statistics accuracy
- Data consistency verification
Usage:
bash tests/integration_test.sh [API_URL] [REDIRECT_URL]
# Examples:
bash tests/integration_test.sh http://localhost:8080 http://localhost:3000
bash tests/integration_test.sh http://api.example.com http://r.example.comConcurrent load and stress testing to verify data consistency under high load:
Test Coverage (6 tests):
- Concurrent URL creation (configurable concurrency level)
- Concurrent redirects to same URL (click counting accuracy)
- Mixed concurrent operations (creates, gets, redirects)
- Rapid state changes under concurrent load
- High-frequency statistics updates (200 redirects)
- List endpoint under concurrent load
Usage:
bash tests/concurrent_test.sh [API_URL] [REDIRECT_URL] [CONCURRENCY]
# Examples:
bash tests/concurrent_test.sh http://localhost:8080 http://localhost:3000 100
bash tests/concurrent_test.sh http://api.example.com http://r.example.com 200Performance benchmark suite to measure throughput and latency under various load conditions:
Focus Areas:
- Redirect Endpoint (primary focus - caching optimizations)
- Single hot URL @ 1000 concurrency
- Single hot URL @ 5000 concurrency
- Distributed load across 100 URLs
- Extreme load @ 10,000 concurrency
- Management Endpoints (expected lower performance - database queries)
- POST /api/urls (create)
- GET /api/urls/:code (read single)
- GET /api/urls (list)
- PUT /api/urls/:code/deactivate (update)
- GET /api/health (health check)
Tools Used:
- wrk: High-performance HTTP benchmarking (primary)
- Apache Bench (ab): Fallback for simple scenarios
Metrics Collected:
- Requests per second (RPS)
- Latency percentiles (p50, p90, p99)
- Error rates
- Transfer rates
Usage:
bash tests/benchmark.sh [API_URL] [REDIRECT_URL] [OUTPUT_DIR] [DURATION]
# Examples:
bash tests/benchmark.sh http://localhost:8080 http://localhost:3000 ./results 30s
bash tests/benchmark.sh http://localhost:8080 http://localhost:3000 ./results 60sSee Also: BENCHMARKS.md for detailed documentation
Automatically runs functional and data consistency tests:
Triggers:
- After successful Docker image build
- Manual workflow dispatch
Test Matrix:
- SQLite Backend: Full integration and concurrent tests
- PostgreSQL Backend: Full integration and concurrent tests
Graceful Shutdown Tests: Both backends are tested with:
- SIGTERM signal handling
- SIGINT signal handling
- Data persistence verification after restart
- Buffered write flush validation
Requirements:
- Docker image must be published to GHCR
- Tests run on ubuntu-24.04 (linux/amd64)
Automatically runs performance benchmarks to validate caching optimizations:
Triggers:
- After successful Docker image build
- Manual workflow dispatch (with configurable duration)
Configuration:
- Database: PostgreSQL 17
- Network:
--network host(bypasses userland proxy for max performance) - Cache: 500k entries, 5s flush interval, 100ms actor flush
- Connections: 50 database connections
Tests:
- Redirect endpoint at various concurrency levels (1k, 5k, 10k)
- All management endpoints (POST, GET, PUT)
- Mixed workload scenarios
Outputs:
- Detailed wrk benchmark results
- JSON structured data for analysis
- Performance report (markdown)
- Service logs
- Artifacts retained for 90 days
See: BENCHMARKS.md for complete documentation
- Verifies click counting accuracy under concurrent load
- Tests buffer flush behavior (Layer 1→2→3)
- Validates data persistence across restarts
- Checks graceful shutdown data integrity
- Simulates 100+ concurrent requests
- Tests race conditions in click counting
- Validates atomic operations
- Stress tests database connection pooling
- All CRUD operations for URLs
- Authentication modes
- Pagination
- Error handling
- Special character handling
- Lynx service running (or use Docker)
- bash shell
- curl command available
# Start Lynx with SQLite
docker run -d \
-p 8080:8080 \
-p 3000:3000 \
-e DATABASE_BACKEND=sqlite \
-e AUTH_MODE=none \
ghcr.io/btreemap/lynx:latest
# Run tests
bash tests/integration_test.sh http://localhost:8080 http://localhost:3000
bash tests/concurrent_test.sh http://localhost:8080 http://localhost:3000 50# Start Lynx
DATABASE_BACKEND=sqlite \
DATABASE_URL="sqlite://./test.db" \
AUTH_MODE=none \
API_HOST=127.0.0.1 \
API_PORT=8080 \
REDIRECT_HOST=127.0.0.1 \
REDIRECT_PORT=3000 \
./target/release/lynx
# Run tests
bash tests/integration_test.sh http://127.0.0.1:8080 http://127.0.0.1:3000
bash tests/concurrent_test.sh http://127.0.0.1:8080 http://127.0.0.1:3000 50==========================================
Running Comprehensive Integration Tests
API URL: http://localhost:8080
Redirect URL: http://localhost:3000
==========================================
Test 1: Health Check
✓ Health check endpoint
Test 2: Get Auth Mode
✓ Auth mode endpoint
...
==========================================
All Integration Tests Passed!
==========================================
Tests will exit with code 1 and show:
Test X: Description
✗ Error message explaining failure
- Ensure Lynx service is running
- Check firewall settings
- Verify correct ports (default: 8080 for API, 3000 for redirects)
- For SQLite: Ensure write permissions to database directory
- For PostgreSQL: Verify connection string and database exists
- Tests have built-in delays for buffer flushes (2-6 seconds)
- Increase sleep times if running on slower systems
- Check CACHE_FLUSH_INTERVAL_SECS and ACTOR_FLUSH_INTERVAL_MS settings
When adding new tests:
- Follow existing test numbering and format
- Add descriptive test names
- Include both positive and negative test cases
- Test concurrent scenarios where applicable
- Update this README with new test coverage