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,10 +1,13 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartProxy } from '../ts/index.js';
|
||||
import * as http from 'http';
|
||||
import { findFreePorts, assertPortsFree } from './helpers/port-allocator.js';
|
||||
|
||||
tap.test('should forward HTTP connections on port 8080', async (tapTest) => {
|
||||
const [PROXY_PORT, TARGET_PORT] = await findFreePorts(2);
|
||||
|
||||
// Create a mock HTTP server to act as our target
|
||||
const targetPort = 47732;
|
||||
const targetPort = TARGET_PORT;
|
||||
let receivedRequest = false;
|
||||
let receivedPath = '';
|
||||
|
||||
@@ -36,7 +39,7 @@ tap.test('should forward HTTP connections on port 8080', async (tapTest) => {
|
||||
routes: [{
|
||||
name: 'test-route',
|
||||
match: {
|
||||
ports: 47730
|
||||
ports: PROXY_PORT
|
||||
// Remove domain restriction for HTTP connections
|
||||
// Domain matching happens after HTTP headers are received
|
||||
},
|
||||
@@ -46,16 +49,16 @@ tap.test('should forward HTTP connections on port 8080', async (tapTest) => {
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
|
||||
await proxy.start();
|
||||
|
||||
|
||||
// Give the proxy a moment to fully initialize
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
|
||||
// Make an HTTP request to port 8080
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: 47730,
|
||||
port: PROXY_PORT,
|
||||
path: '/.well-known/acme-challenge/test-token',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
@@ -97,14 +100,17 @@ tap.test('should forward HTTP connections on port 8080', async (tapTest) => {
|
||||
await new Promise<void>((resolve) => {
|
||||
targetServer.close(() => resolve());
|
||||
});
|
||||
|
||||
|
||||
// Wait a bit to ensure port is fully released
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
await assertPortsFree([PROXY_PORT, TARGET_PORT]);
|
||||
});
|
||||
|
||||
tap.test('should handle basic HTTP request forwarding', async (tapTest) => {
|
||||
const [PROXY_PORT, TARGET_PORT] = await findFreePorts(2);
|
||||
|
||||
// Create a simple target server
|
||||
const targetPort = 47733;
|
||||
const targetPort = TARGET_PORT;
|
||||
let receivedRequest = false;
|
||||
|
||||
const targetServer = http.createServer((req, res) => {
|
||||
@@ -126,7 +132,7 @@ tap.test('should handle basic HTTP request forwarding', async (tapTest) => {
|
||||
routes: [{
|
||||
name: 'simple-forward',
|
||||
match: {
|
||||
ports: 47731
|
||||
ports: PROXY_PORT
|
||||
// Remove domain restriction for HTTP connections
|
||||
},
|
||||
action: {
|
||||
@@ -142,7 +148,7 @@ tap.test('should handle basic HTTP request forwarding', async (tapTest) => {
|
||||
// Make request
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: 47731,
|
||||
port: PROXY_PORT,
|
||||
path: '/test',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
@@ -184,9 +190,10 @@ tap.test('should handle basic HTTP request forwarding', async (tapTest) => {
|
||||
await new Promise<void>((resolve) => {
|
||||
targetServer.close(() => resolve());
|
||||
});
|
||||
|
||||
|
||||
// Wait a bit to ensure port is fully released
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
await assertPortsFree([PROXY_PORT, TARGET_PORT]);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user