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:
@@ -1,9 +1,12 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as net from 'net';
|
||||
import { SmartProxy } from '../ts/proxies/smart-proxy/smart-proxy.js';
|
||||
import { findFreePorts, assertPortsFree } from './helpers/port-allocator.js';
|
||||
|
||||
// Test to verify port forwarding works correctly
|
||||
tap.test('forward connections should not be immediately closed', async (t) => {
|
||||
const [PROXY_PORT, SERVER_PORT] = await findFreePorts(2);
|
||||
|
||||
// Create a backend server that accepts connections
|
||||
const testServer = net.createServer((socket) => {
|
||||
console.log('Client connected to test server');
|
||||
@@ -21,8 +24,8 @@ tap.test('forward connections should not be immediately closed', async (t) => {
|
||||
|
||||
// Listen on a non-privileged port
|
||||
await new Promise<void>((resolve) => {
|
||||
testServer.listen(47721, '127.0.0.1', () => {
|
||||
console.log('Test server listening on port 47721');
|
||||
testServer.listen(SERVER_PORT, '127.0.0.1', () => {
|
||||
console.log(`Test server listening on port ${SERVER_PORT}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -34,13 +37,13 @@ tap.test('forward connections should not be immediately closed', async (t) => {
|
||||
{
|
||||
name: 'forward-test',
|
||||
match: {
|
||||
ports: 47720,
|
||||
ports: PROXY_PORT,
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
targets: [{
|
||||
host: '127.0.0.1',
|
||||
port: 47721,
|
||||
port: SERVER_PORT,
|
||||
}],
|
||||
},
|
||||
},
|
||||
@@ -51,7 +54,7 @@ tap.test('forward connections should not be immediately closed', async (t) => {
|
||||
|
||||
// Create a client connection through the proxy
|
||||
const client = net.createConnection({
|
||||
port: 47720,
|
||||
port: PROXY_PORT,
|
||||
host: '127.0.0.1',
|
||||
});
|
||||
|
||||
@@ -105,6 +108,7 @@ tap.test('forward connections should not be immediately closed', async (t) => {
|
||||
client.end();
|
||||
await smartProxy.stop();
|
||||
testServer.close();
|
||||
await assertPortsFree([PROXY_PORT, SERVER_PORT]);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user