@bcoders.gr/eth-provider
Version:
High-Performance IPC Ethereum Provider with Advanced Optimizations - Refactored for Better Performance
190 lines (153 loc) โข 6.56 kB
JavaScript
import CacheManagerTests from './unit/cache-manager.test.js';
import JSONParserTests from './unit/json-parser.test.js';
import RequestPoolTests from './unit/request-pool.test.js';
import StressTests from './integration/stress-test.js';
/**
* Comprehensive test runner for all provider tests
*/
class TestRunner {
constructor() {
this.totalTests = 0;
this.passedTests = 0;
this.failedTests = 0;
this.startTime = null;
}
async runAllTests() {
console.log('๐ Starting Comprehensive Test Suite\n');
console.log('=====================================');
this.startTime = Date.now();
try {
// Unit Tests
console.log('๐ UNIT TESTS');
console.log('=============\n');
await this.runUnitTests();
console.log('\n๐ INTEGRATION & STRESS TESTS');
console.log('==============================\n');
await this.runIntegrationTests();
this.printFinalSummary();
} catch (error) {
console.error('โ Test runner failed:', error);
process.exit(1);
}
}
async runUnitTests() {
// Cache Manager Tests
console.log('๐งช Cache Manager Unit Tests');
const cacheTests = new CacheManagerTests();
await cacheTests.runAllTests();
this.aggregateResults(cacheTests.testResults);
// JSON Parser Tests
console.log('๐งช JSON Parser Unit Tests');
const parserTests = new JSONParserTests();
await parserTests.runAllTests();
this.aggregateResults(parserTests.testResults);
// Request Pool Tests
console.log('๐งช Request Pool Unit Tests');
const poolTests = new RequestPoolTests();
await poolTests.runAllTests();
this.aggregateResults(poolTests.testResults);
}
async runIntegrationTests() {
// Stress and Integration Tests
console.log('๐งช Stress & Integration Tests');
const stressTests = new StressTests();
await stressTests.runAllTests();
this.aggregateResults(stressTests.testResults);
}
aggregateResults(testResults) {
testResults.forEach(result => {
this.totalTests++;
if (result.status === 'PASS') {
this.passedTests++;
} else {
this.failedTests++;
}
});
}
printFinalSummary() {
const endTime = Date.now();
const duration = endTime - this.startTime;
const successRate = ((this.passedTests / this.totalTests) * 100).toFixed(1);
console.log('\n๐ฏ FINAL TEST SUMMARY');
console.log('=====================');
console.log(`๐ Total Tests: ${this.totalTests}`);
console.log(`โ
Passed: ${this.passedTests}`);
console.log(`โ Failed: ${this.failedTests}`);
console.log(`๐ Success Rate: ${successRate}%`);
console.log(`โฑ๏ธ Duration: ${duration}ms`);
console.log(`๐ Average: ${(duration / this.totalTests).toFixed(2)}ms per test`);
if (this.failedTests === 0) {
console.log('\n๐ ALL TESTS PASSED! ๐');
console.log('The refactored IPC Provider is working perfectly!');
} else {
console.log(`\nโ ๏ธ ${this.failedTests} test(s) failed. Please review the results above.`);
}
console.log('=====================\n');
// Exit with appropriate code
process.exit(this.failedTests === 0 ? 0 : 1);
}
}
// Performance validation test
async function validatePerformanceImprovements() {
console.log('๐ฌ Performance Validation');
console.log('=========================\n');
try {
// Import and run performance benchmarks
const { default: PerformanceBenchmark } = await import('../benchmarks/performance-test.js');
const benchmark = new PerformanceBenchmark();
console.log('Running performance benchmarks to validate improvements...\n');
await benchmark.runAllTests();
console.log('โ
Performance validation completed\n');
} catch (error) {
console.log('โ ๏ธ Performance validation skipped:', error.message);
console.log(' (This is normal if running without benchmark dependencies)\n');
}
}
// Component integration test
async function validateComponentIntegration() {
console.log('๐ Component Integration Validation');
console.log('===================================\n');
try {
const { IPCProvider } = await import('../index.js');
// Test that all components work together
const provider = new IPCProvider('/tmp/integration-test.ipc', {
cacheEnabled: true,
batchRequests: true,
metricsEnabled: true,
poolSize: 10
});
// Test component interaction
const stats = provider.getStats();
console.log('โ
All components loaded successfully');
console.log('โ
Provider initialization successful');
console.log('โ
Statistics gathering functional');
console.log(`โ
Cache system: ${stats.cache.enabled ? 'enabled' : 'disabled'}`);
console.log(`โ
Batch processing: ${stats.batch ? 'available' : 'unavailable'}`);
console.log(`โ
Metrics tracking: ${stats.metrics.enabled ? 'enabled' : 'disabled'}`);
console.log(`โ
Object pooling: ${stats.pool.totalPoolSize} objects ready`);
console.log('\n๐ฏ Component integration validation passed!\n');
} catch (error) {
console.error('โ Component integration validation failed:', error);
throw error;
}
}
// Main execution
async function main() {
console.log('๐งช IPC Provider v2.0 - Comprehensive Test Suite');
console.log('================================================\n');
// Validate component integration first
await validateComponentIntegration();
// Run performance validation
await validatePerformanceImprovements();
// Run comprehensive test suite
const testRunner = new TestRunner();
await testRunner.runAllTests();
}
// Run if executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch(error => {
console.error('๐ฅ Test suite failed:', error);
process.exit(1);
});
}
export default TestRunner;