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:
2026-02-24 20:56:37 +00:00
parent 755c81c042
commit 33cd5330c4
24 changed files with 535 additions and 560 deletions

View File

@@ -1,12 +1,15 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as net from 'net';
import { SmartProxy } from '../ts/index.js';
import { findFreePorts, assertPortsFree } from './helpers/port-allocator.js';
tap.test('should handle async handler that sets up listeners after delay', async () => {
const [PORT] = await findFreePorts(1);
const proxy = new SmartProxy({
routes: [{
name: 'delayed-setup-handler',
match: { ports: 7777 },
match: { ports: PORT },
action: {
type: 'socket-handler',
socketHandler: async (socket, context) => {
@@ -41,7 +44,7 @@ tap.test('should handle async handler that sets up listeners after delay', async
});
await new Promise<void>((resolve, reject) => {
client.connect(7777, 'localhost', () => {
client.connect(PORT, 'localhost', () => {
// Send initial data immediately - this tests the race condition
client.write('initial-message\n');
resolve();
@@ -78,6 +81,7 @@ tap.test('should handle async handler that sets up listeners after delay', async
expect(response).toContain('RECEIVED: test-message');
await proxy.stop();
await assertPortsFree([PORT]);
});
export default tap.start();