stock-bot/libs/queue/test-simplified-api.ts

85 lines
2.4 KiB
TypeScript

#!/usr/bin/env bun
// Quick test of the simplified API
import { initializeBatchCache, processItems, QueueManager } from './src/index.js';
async function testSimplifiedAPI() {
console.log('🚀 Testing simplified queue API...');
// Create queue manager
const queueManager = new QueueManager({
queueName: 'di2',
workers: 2,
concurrency: 2,
});
// Register a simple provider
queueManager.registerProvider('test-provider', {
'process-item': async payload => {
console.log(`✅ Processing item: ${JSON.stringify(payload)}`);
await new Promise(resolve => setTimeout(resolve, 100));
return { processed: true, originalData: payload };
},
});
try {
await queueManager.initialize();
await initializeBatchCache(queueManager);
console.log('📋 Testing with simple array...');
// Test 1: Simple array of numbers
const numbers = [1, 2, 3, 4, 5];
const result1 = await processItems(numbers, queueManager, {
totalDelayHours: 0.0014, // ~5 seconds (5/3600 hours)
useBatching: false,
provider: 'test-provider',
operation: 'process-item',
});
console.log('🎯 Numbers result:', result1);
// Test 2: Array of objects
const objects = [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
{ id: 3, name: 'Item 3' },
];
const result2 = await processItems(objects, queueManager, {
totalDelayHours: 0.0014, // ~5 seconds
useBatching: true,
batchSize: 2,
provider: 'test-provider',
operation: 'process-item',
});
console.log('🎯 Objects result:', result2);
// Test 3: Array of strings (symbols)
const symbols = Array.from({ length: 1000 }, (_, i) => `Symbol-${i + 1}`);
console.log('📋 Testing with symbols...');
const result3 = await processItems(symbols, queueManager, {
totalDelayHours: 0.0008, // ~3 seconds
useBatching: true,
batchSize: 1,
provider: 'test-provider',
operation: 'process-item',
});
console.log('🎯 Symbols result:', result3);
console.log('✨ All tests completed successfully!');
console.log('🏆 The simplified API is working correctly!');
} catch (error) {
console.error('❌ Test failed:', error);
} finally {
// Clean shutdown
setTimeout(async () => {
await queueManager.shutdown();
console.log('🔄 Shutdown complete');
process.exit(0);
}, 10000000);
}
}
testSimplifiedAPI().catch(console.error);