fix(smartproxy): improve certificate manager mocking in tests, enhance IPv6 validation, and record initial bytes for connection metrics

This commit is contained in:
2026-01-30 19:52:36 +00:00
parent 1d1e5062a6
commit 2068b7a1ad
15 changed files with 230 additions and 119 deletions

View File

@@ -144,33 +144,51 @@ tap.test('should track throughput correctly', async (tools) => {
// Clean up
client.destroy();
await tools.delayFor(100);
// Wait for connection cleanup with retry
for (let i = 0; i < 10; i++) {
await tools.delayFor(100);
if (metrics.connections.active() === 0) break;
}
// Verify connection was cleaned up
expect(metrics.connections.active()).toEqual(0);
});
tap.test('should track multiple connections and routes', async (tools) => {
const metrics = smartProxyInstance.getMetrics();
// Ensure we start with 0 connections
const initialActive = metrics.connections.active();
if (initialActive > 0) {
console.log(`Warning: Starting with ${initialActive} active connections, waiting for cleanup...`);
for (let i = 0; i < 10; i++) {
await tools.delayFor(100);
if (metrics.connections.active() === 0) break;
}
}
// Create multiple connections
const clients: net.Socket[] = [];
const connectionCount = 5;
for (let i = 0; i < connectionCount; i++) {
const client = new net.Socket();
await new Promise<void>((resolve, reject) => {
client.connect(proxyPort, 'localhost', () => {
resolve();
});
client.on('error', reject);
});
clients.push(client);
}
// Allow connections to be fully established and tracked
await tools.delayFor(100);
// Verify active connections
expect(metrics.connections.active()).toEqual(connectionCount);