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,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();
|
||||
Reference in New Issue
Block a user