fix(smartproxy): upgrade @push.rocks/smartproxy to ^23.1.0 and adapt code/tests for its async getStatistics() API
This commit is contained in:
@@ -197,65 +197,55 @@ tap.test('CERR-03: Network Failures - should handle EHOSTUNREACH', async () => {
|
||||
});
|
||||
|
||||
tap.test('CERR-03: Network Failures - should handle packet loss simulation', async () => {
|
||||
// Create a server that randomly drops data
|
||||
let packetCount = 0;
|
||||
// Create a server that sends a greeting but never responds to commands,
|
||||
// simulating complete packet loss after the initial connection.
|
||||
const lossyServer = net.createServer((socket) => {
|
||||
socket.on('error', () => {});
|
||||
socket.write('220 Lossy server ready\r\n');
|
||||
|
||||
socket.on('data', (data) => {
|
||||
packetCount++;
|
||||
|
||||
// Simulate 30% packet loss
|
||||
if (Math.random() > 0.3) {
|
||||
const command = data.toString().trim();
|
||||
if (command.startsWith('EHLO')) {
|
||||
socket.write('250 OK\r\n');
|
||||
} else if (command === 'QUIT') {
|
||||
socket.write('221 Bye\r\n');
|
||||
socket.end();
|
||||
}
|
||||
}
|
||||
// Otherwise, don't respond (simulate packet loss)
|
||||
|
||||
// Never respond to any commands - simulates total packet loss
|
||||
socket.on('data', () => {
|
||||
// Intentionally drop all data to simulate packet loss
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
lossyServer.listen(2558, () => resolve());
|
||||
});
|
||||
|
||||
|
||||
const client = createSmtpClient({
|
||||
host: 'localhost',
|
||||
port: 2558,
|
||||
secure: false,
|
||||
connectionTimeout: 1000,
|
||||
socketTimeout: 1000 // Short timeout to detect loss
|
||||
connectionTimeout: 2000,
|
||||
socketTimeout: 2000 // Short timeout to detect loss
|
||||
});
|
||||
|
||||
|
||||
let verifyResult = false;
|
||||
let errorOccurred = false;
|
||||
|
||||
|
||||
try {
|
||||
verifyResult = await client.verify();
|
||||
if (verifyResult) {
|
||||
console.log('✅ Connected despite simulated packet loss');
|
||||
console.log('Connection succeeded unexpectedly');
|
||||
} else {
|
||||
console.log('✅ Connection failed due to packet loss');
|
||||
}
|
||||
} catch (error) {
|
||||
errorOccurred = true;
|
||||
console.log(`✅ Packet loss detected after ${packetCount} packets: ${error.message}`);
|
||||
console.log(`✅ Packet loss detected: ${error.message}`);
|
||||
}
|
||||
|
||||
// Either verification failed or an error occurred - both are expected with packet loss
|
||||
|
||||
// verify() must have returned false or thrown - both indicate packet loss was detected
|
||||
expect(!verifyResult || errorOccurred).toBeTrue();
|
||||
|
||||
|
||||
// Clean up client first
|
||||
try {
|
||||
await client.close();
|
||||
} catch (closeError) {
|
||||
// Ignore close errors in this test
|
||||
}
|
||||
|
||||
|
||||
// Then close server
|
||||
await new Promise<void>((resolve) => {
|
||||
lossyServer.close(() => resolve());
|
||||
|
||||
Reference in New Issue
Block a user