fix(tests): use high non-privileged ports in tests to avoid conflicts and CI failures

This commit is contained in:
2026-02-21 13:27:55 +00:00
parent d4739045cd
commit 9368226ce0
9 changed files with 55 additions and 48 deletions

View File

@@ -14,8 +14,8 @@ import type { IRouteConfig, IRouteContext } from '../ts/proxies/smart-proxy/mode
let testServers: Array<{ server: net.Server; port: number }> = [];
let smartProxy: SmartProxy;
const TEST_PORT_START = 4000;
const PROXY_PORT_START = 5000;
const TEST_PORT_START = 47750;
const PROXY_PORT_START = 48750;
const TEST_DATA = 'Hello through dynamic port mapper!';
// Cleanup function to close all servers and proxies
@@ -103,9 +103,9 @@ function createTestClient(port: number, data: string): Promise<string> {
tap.test('setup port mapping test environment', async () => {
// Create multiple test servers on different ports
await Promise.all([
createTestServer(TEST_PORT_START), // Server on port 4000
createTestServer(TEST_PORT_START + 1), // Server on port 4001
createTestServer(TEST_PORT_START + 2), // Server on port 4002
createTestServer(TEST_PORT_START), // Server on port 47750
createTestServer(TEST_PORT_START + 1), // Server on port 47751
createTestServer(TEST_PORT_START + 2), // Server on port 47752
]);
// Create a SmartProxy with dynamic port mapping routes
@@ -119,7 +119,7 @@ tap.test('setup port mapping test environment', async () => {
name: 'Identity Port Mapping'
}),
// Offset port mapping from 5001 to 4001 (offset -1000)
// Offset port mapping from 48751 to 47751 (offset -1000)
createOffsetPortMappingRoute({
ports: PROXY_PORT_START + 1,
targetHost: 'localhost',
@@ -170,13 +170,13 @@ tap.test('setup port mapping test environment', async () => {
await smartProxy.start();
});
// Test 1: Simple identity port mapping (5000 -> 4000)
// Test 1: Simple identity port mapping (48750 -> 47750)
tap.test('should map port using identity function', async () => {
const response = await createTestClient(PROXY_PORT_START, TEST_DATA);
expect(response).toEqual(`Server ${TEST_PORT_START} says: ${TEST_DATA}`);
});
// Test 2: Offset port mapping (5001 -> 4001)
// Test 2: Offset port mapping (48751 -> 47751)
tap.test('should map port using offset function', async () => {
const response = await createTestClient(PROXY_PORT_START + 1, TEST_DATA);
expect(response).toEqual(`Server ${TEST_PORT_START + 1} says: ${TEST_DATA}`);