fix(rustproxy): Use cooperative cancellation for background tasks, prune stale caches and metric entries, and switch tests to dynamic port allocation to avoid port conflicts
This commit is contained in:
@@ -7,15 +7,16 @@ import * as net from 'net';
|
||||
import * as tls from 'tls';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { findFreePorts, assertPortsFree } from './helpers/port-allocator.js';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Port assignments (47600–47620 range to avoid conflicts)
|
||||
// Port assignments (dynamically allocated to avoid conflicts)
|
||||
// ---------------------------------------------------------------------------
|
||||
const HTTP_ECHO_PORT = 47600; // backend HTTP echo server
|
||||
const PROXY_HTTP_PORT = 47601; // SmartProxy plain HTTP forwarding
|
||||
const PROXY_HTTPS_PORT = 47602; // SmartProxy TLS-terminate HTTPS forwarding
|
||||
const TCP_ECHO_PORT = 47603; // backend TCP echo server
|
||||
const PROXY_TCP_PORT = 47604; // SmartProxy plain TCP forwarding
|
||||
let HTTP_ECHO_PORT: number;
|
||||
let PROXY_HTTP_PORT: number;
|
||||
let PROXY_HTTPS_PORT: number;
|
||||
let TCP_ECHO_PORT: number;
|
||||
let PROXY_TCP_PORT: number;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared state
|
||||
@@ -88,6 +89,8 @@ async function waitForMetrics(
|
||||
// 1. Setup backend servers
|
||||
// ===========================================================================
|
||||
tap.test('setup - backend servers', async () => {
|
||||
[HTTP_ECHO_PORT, PROXY_HTTP_PORT, PROXY_HTTPS_PORT, TCP_ECHO_PORT, PROXY_TCP_PORT] = await findFreePorts(5);
|
||||
|
||||
// HTTP echo server: POST → echo:<body>, GET → ok
|
||||
httpEchoServer = http.createServer((req, res) => {
|
||||
if (req.method === 'POST') {
|
||||
@@ -467,6 +470,8 @@ tap.test('cleanup', async () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
await assertPortsFree([HTTP_ECHO_PORT, PROXY_HTTP_PORT, PROXY_HTTPS_PORT, TCP_ECHO_PORT, PROXY_TCP_PORT]);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user