This document provides comprehensive information about testing the Traversion production debugging platform.
The Traversion test suite includes:
- Unit Tests: Test individual components in isolation
- Integration Tests: Test complete workflows and API endpoints
- Performance Tests: Ensure system handles load and concurrent operations
- Security Tests: Validate authentication, authorization, and tenant isolation
test/
├── unit/ # Unit tests
│ ├── causality.test.js # Causality engine tests
│ ├── storage.test.js # Storage layer tests
│ └── temporal-query.test.js # TimeQL engine tests
├── integration/ # Integration tests
│ ├── api.test.js # API endpoint tests
│ └── auth.test.js # Authentication tests
├── setup.js # Global test setup
└── README.md # This file
-
PostgreSQL with TimescaleDB
# Install TimescaleDB # See: https://docs.timescale.com/install/
-
Redis
# Install Redis brew install redis # macOS sudo apt install redis # Ubuntu
-
Create test database:
# Run the setup script ./scripts/setup-test-db.sh # Or manually: createdb traversion_test psql traversion_test -c "CREATE EXTENSION timescaledb" psql traversion_test -f init-db/01-schema.sql
-
Configure environment variables:
export TEST_DB_HOST=localhost export TEST_DB_PORT=5432 export TEST_DB_NAME=traversion_test export TEST_DB_USER=traversion export TEST_DB_PASSWORD=traversion_secret export TEST_REDIS_HOST=localhost export TEST_REDIS_PORT=6379
npm installnpm test# Unit tests only
npm run test:unit
# Integration tests only
npm run test:integration
# Specific test files
npm run test:auth # Authentication tests
npm run test:causality # Causality engine tests
npm run test:storage # Storage layer tests# Run tests with coverage report
npm run test:coverage
# View coverage report
open coverage/lcov-report/index.html# Run tests in watch mode for development
npm run test:watchTests are configured in jest.config.js:
- ES Module Support: Full ES6 module support
- Test Environment: Node.js environment
- Coverage Thresholds: Minimum 80% line coverage
- Test Timeout: 30 seconds for integration tests
Test-specific environment variables:
NODE_ENV=test # Test environment
LOG_LEVEL=error # Reduce log noise
JWT_SECRET=test-jwt-secret # Test JWT secret
API_KEY_SECRET=test-api-secret # Test API key secretimport { describe, it, beforeAll, afterAll, expect } from '@jest/globals';
describe('Component Name', () => {
beforeAll(async () => {
// Setup for all tests
});
afterAll(async () => {
// Cleanup after all tests
});
describe('Feature Group', () => {
it('should do something specific', () => {
// Test implementation
expect(result).toBe(expected);
});
});
});Global test utilities available in all tests:
// Generate test data
const event = global.testUtils.createTestEvent({
eventType: 'custom.test',
serviceId: 'test-service'
});
const user = global.testUtils.createTestUser({
email: 'test@example.com',
role: 'admin'
});
const tenant = global.testUtils.createTestTenant({
name: 'Test Organization'
});
// Time utilities
const { start, end } = global.testUtils.timeRange(2, 0); // 2 hours ago to now
await global.testUtils.wait(1000); // Wait 1 second- Isolation: Each test should be independent
- Cleanup: Always clean up test data
- Descriptive Names: Use clear, descriptive test names
- Assertions: Use specific assertions
- Async/Await: Handle promises properly
Test individual components:
describe('CausalityEngine', () => {
it('should detect temporal causality', () => {
const engine = new CausalityEngine();
// Test causality detection logic
});
});Test complete workflows:
describe('Event Ingestion Flow', () => {
it('should ingest, process, and store events', async () => {
// Test complete event flow from API to database
});
});Test security features:
describe('Multi-tenant Isolation', () => {
it('should prevent cross-tenant data access', async () => {
// Test tenant isolation
});
});Test system performance:
describe('High Volume Processing', () => {
it('should handle 10k events efficiently', async () => {
// Test performance under load
});
});Create .github/workflows/test.yml:
name: Test Suite
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: timescale/timescaledb:latest-pg14
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Setup test database
run: ./scripts/setup-test-db.sh
env:
TEST_DB_HOST: localhost
TEST_DB_USER: postgres
TEST_DB_PASSWORD: postgres
- name: Run tests
run: npm run test:coverage
env:
TEST_DB_HOST: localhost
TEST_DB_USER: postgres
TEST_DB_PASSWORD: postgres
- name: Upload coverage
uses: codecov/codecov-action@v3# Run specific test with debugging
node --inspect-brk ./node_modules/.bin/jest test/unit/causality.test.js# Start API server in debug mode
DEBUG=* npm run dev
# Run API tests against running server
npm run test:integration-
Database Connection Issues:
- Verify PostgreSQL is running
- Check connection parameters
- Ensure TimescaleDB extension is installed
-
Redis Connection Issues:
- Verify Redis is running
- Check Redis configuration
-
Test Timeouts:
- Increase Jest timeout in
jest.config.js - Check for hanging promises
- Increase Jest timeout in
-
Authentication Failures:
- Verify JWT secrets are set
- Check user creation and token generation
- Overall Coverage: 80%+ lines, 75%+ functions
- Critical Components: 90%+ coverage
- Authentication service
- Causality engine
- Storage layer
- API Endpoints: 85%+ coverage
Tests should verify these performance targets:
- Event Ingestion: 1000+ events/second
- Query Response: <500ms for time range queries
- Causality Detection: <100ms per event
- Memory Usage: <1GB for 100k events
- Database Operations: <50ms average
Security tests verify:
- Authentication: JWT and API key validation
- Authorization: Role-based access control
- Tenant Isolation: Data separation between tenants
- Input Validation: SQL injection prevention
- Rate Limiting: API abuse prevention
Monitor test suite health:
- Test Duration: Should remain under 5 minutes
- Flaky Tests: Identify and fix unstable tests
- Coverage Trends: Track coverage over time
- Performance Degradation: Monitor test execution time
When adding new features:
- Write tests first (TDD approach)
- Ensure tests pass locally
- Maintain or improve coverage
- Update test documentation
- Add integration tests for new APIs
For questions about testing, see the development team or create an issue in the repository.