dcrouter/test/suite/smtpclient_performance/test.cperf-08.dns-caching.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-05-26 16:14:49 +00:00
import { tap, expect } from '@git.zone/tstest/tapbundle';
import { createTestServer } from '../../helpers/server.loader.js';
import { createTestSmtpClient } from '../../helpers/smtp.client.js';
2025-05-24 18:12:08 +00:00
import { Email } from '../../../ts/mail/core/classes.email.js';
2025-05-26 16:14:49 +00:00
tap.test('CPERF-08: DNS Caching Tests', async () => {
console.log('\n🌐 Testing SMTP Client DNS Caching');
2025-05-24 18:12:08 +00:00
console.log('=' .repeat(60));
2025-05-26 16:14:49 +00:00
const testServer = await createTestServer({});
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
try {
console.log('\nTest: DNS caching with multiple connections');
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
// Create multiple clients to test DNS caching
const clients = [];
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
for (let i = 0; i < 3; i++) {
const smtpClient = createTestSmtpClient({
2025-05-24 18:12:08 +00:00
host: testServer.hostname,
2025-05-26 16:14:49 +00:00
port: testServer.port
2025-05-24 18:12:08 +00:00
});
2025-05-26 16:14:49 +00:00
clients.push(smtpClient);
console.log(` ✓ Client ${i + 1} created (DNS should be cached)`);
2025-05-24 18:12:08 +00:00
}
2025-05-26 16:14:49 +00:00
// Send email with first client
const email = new Email({
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'DNS Caching Test',
text: 'Testing DNS caching efficiency'
2025-05-24 18:12:08 +00:00
});
2025-05-26 16:14:49 +00:00
const result = await clients[0].sendMail(email);
console.log(' ✓ Email sent successfully');
expect(result).toBeDefined();
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
// Clean up all clients
clients.forEach(client => client.close());
console.log(' ✓ All clients closed');
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
console.log('\n✅ CPERF-08: DNS caching tests completed');
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
} finally {
testServer.server.close();
}
});
2025-05-24 18:12:08 +00:00
2025-05-26 16:14:49 +00:00
tap.start();