()
| 87 | } |
| 88 | |
| 89 | async function testConnectionPooling() { |
| 90 | console.log("\n🔄 Testing connection pooling..."); |
| 91 | |
| 92 | try { |
| 93 | // Test multiple concurrent connections |
| 94 | const promises = Array.from({ length: 5 }, async (_, i) => { |
| 95 | const client = await mongoDb; |
| 96 | const db = client.db(process.env.DATABASE_NAME || 'pulse-db'); |
| 97 | const startTime = Date.now(); |
| 98 | |
| 99 | // Simple operation |
| 100 | await db.command({ ping: 1 }); |
| 101 | |
| 102 | const duration = Date.now() - startTime; |
| 103 | console.log(` Connection ${i + 1}: ${duration}ms`); |
| 104 | return duration; |
| 105 | }); |
| 106 | |
| 107 | const results = await Promise.all(promises); |
| 108 | const avgTime = results.reduce((a, b) => a + b, 0) / results.length; |
| 109 | |
| 110 | console.log(` 📊 Average connection time: ${avgTime.toFixed(2)}ms`); |
| 111 | console.log(" ✅ Connection pooling working correctly"); |
| 112 | |
| 113 | } catch (error) { |
| 114 | console.error(" ❌ Connection pooling test failed:", error); |
| 115 | throw error; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | async function main() { |
| 120 | try { |
no outgoing calls
no test coverage detected
searching dependent graphs…