feat: add comprehensive performance benchmark tracking system
- Create benchmark test suites for critical operations: - Node loading performance - Database query performance - Search operations performance - Validation performance - MCP tool execution performance - Add GitHub Actions workflow for benchmark tracking: - Runs on push to main and PRs - Uses github-action-benchmark for historical tracking - Comments on PRs with performance results - Alerts on >10% performance regressions - Stores results in GitHub Pages - Create benchmark infrastructure: - Custom Vitest benchmark configuration - JSON reporter for CI results - Result formatter for github-action-benchmark - Performance threshold documentation - Add supporting utilities: - SQLiteStorageService for benchmark database setup - MCPEngine wrapper for testing MCP tools - Test factories for generating benchmark data - Enhanced NodeRepository with benchmark methods - Document benchmark system: - Comprehensive benchmark guide in docs/BENCHMARKS.md - Performance thresholds in .github/BENCHMARK_THRESHOLDS.md - README for benchmarks directory - Integration with existing test suite The benchmark system will help monitor performance over time and catch regressions before they reach production. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
128
tests/utils/DATABASE_UTILITIES_SUMMARY.md
Normal file
128
tests/utils/DATABASE_UTILITIES_SUMMARY.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# Database Testing Utilities Summary
|
||||
|
||||
## Overview
|
||||
We've created comprehensive database testing utilities for the n8n-mcp project that provide a complete toolkit for database-related testing scenarios.
|
||||
|
||||
## Created Files
|
||||
|
||||
### 1. `/tests/utils/database-utils.ts`
|
||||
The main utilities file containing:
|
||||
- **createTestDatabase()** - Creates test databases (in-memory or file-based)
|
||||
- **seedTestNodes()** - Seeds test node data
|
||||
- **seedTestTemplates()** - Seeds test template data
|
||||
- **createTestNode()** - Factory for creating test nodes
|
||||
- **createTestTemplate()** - Factory for creating test templates
|
||||
- **resetDatabase()** - Clears and reinitializes database
|
||||
- **createDatabaseSnapshot()** - Creates database state snapshots
|
||||
- **restoreDatabaseSnapshot()** - Restores from snapshots
|
||||
- **loadFixtures()** - Loads data from JSON fixtures
|
||||
- **dbHelpers** - Collection of common database operations
|
||||
- **createMockDatabaseAdapter()** - Creates mock adapter for unit tests
|
||||
- **withTransaction()** - Transaction testing helper
|
||||
- **measureDatabaseOperation()** - Performance measurement helper
|
||||
|
||||
### 2. `/tests/unit/utils/database-utils.test.ts`
|
||||
Comprehensive unit tests covering all utility functions with 22 test cases.
|
||||
|
||||
### 3. `/tests/fixtures/database/test-nodes.json`
|
||||
Example fixture file showing the correct format for nodes and templates.
|
||||
|
||||
### 4. `/tests/examples/using-database-utils.test.ts`
|
||||
Practical examples showing how to use the utilities in real test scenarios.
|
||||
|
||||
### 5. `/tests/integration/database-integration.test.ts`
|
||||
Integration test examples demonstrating complex database operations.
|
||||
|
||||
### 6. `/tests/utils/README.md`
|
||||
Documentation explaining how to use the database utilities.
|
||||
|
||||
## Key Features
|
||||
|
||||
### 1. Flexible Database Creation
|
||||
```typescript
|
||||
// In-memory for unit tests (fast, isolated)
|
||||
const testDb = await createTestDatabase();
|
||||
|
||||
// File-based for integration tests
|
||||
const testDb = await createTestDatabase({
|
||||
inMemory: false,
|
||||
dbPath: './test.db'
|
||||
});
|
||||
```
|
||||
|
||||
### 2. Easy Data Seeding
|
||||
```typescript
|
||||
// Seed with defaults
|
||||
await seedTestNodes(testDb.nodeRepository);
|
||||
|
||||
// Seed with custom data
|
||||
await seedTestNodes(testDb.nodeRepository, [
|
||||
{ nodeType: 'custom.node', displayName: 'Custom' }
|
||||
]);
|
||||
```
|
||||
|
||||
### 3. State Management
|
||||
```typescript
|
||||
// Create snapshot
|
||||
const snapshot = await createDatabaseSnapshot(testDb.adapter);
|
||||
|
||||
// Do risky operations...
|
||||
|
||||
// Restore if needed
|
||||
await restoreDatabaseSnapshot(testDb.adapter, snapshot);
|
||||
```
|
||||
|
||||
### 4. Fixture Support
|
||||
```typescript
|
||||
// Load complex scenarios from JSON
|
||||
await loadFixtures(testDb.adapter, './fixtures/scenario.json');
|
||||
```
|
||||
|
||||
### 5. Helper Functions
|
||||
```typescript
|
||||
// Common operations
|
||||
dbHelpers.countRows(adapter, 'nodes');
|
||||
dbHelpers.nodeExists(adapter, 'node-type');
|
||||
dbHelpers.getAllNodeTypes(adapter);
|
||||
dbHelpers.clearTable(adapter, 'templates');
|
||||
```
|
||||
|
||||
## TypeScript Support
|
||||
All utilities are fully typed with proper interfaces:
|
||||
- `TestDatabase`
|
||||
- `TestDatabaseOptions`
|
||||
- `DatabaseSnapshot`
|
||||
|
||||
## Performance Considerations
|
||||
- In-memory databases for unit tests (milliseconds)
|
||||
- File-based databases for integration tests
|
||||
- Transaction support for atomic operations
|
||||
- Performance measurement utilities included
|
||||
|
||||
## Best Practices
|
||||
1. Always cleanup databases after tests
|
||||
2. Use in-memory for unit tests
|
||||
3. Use snapshots for complex state management
|
||||
4. Keep fixtures versioned with your tests
|
||||
5. Test both empty and populated database states
|
||||
|
||||
## Integration with Existing Code
|
||||
The utilities work seamlessly with:
|
||||
- `DatabaseAdapter` from the main codebase
|
||||
- `NodeRepository` for node operations
|
||||
- `TemplateRepository` for template operations
|
||||
- All existing database schemas
|
||||
|
||||
## Testing Coverage
|
||||
- ✅ All utilities have comprehensive unit tests
|
||||
- ✅ Integration test examples provided
|
||||
- ✅ Performance testing included
|
||||
- ✅ Transaction testing supported
|
||||
- ✅ Mock adapter for isolated unit tests
|
||||
|
||||
## Usage in CI/CD
|
||||
The utilities support:
|
||||
- Parallel test execution (isolated databases)
|
||||
- Consistent test data across runs
|
||||
- Fast execution with in-memory databases
|
||||
- No external dependencies required
|
||||
Reference in New Issue
Block a user