This commit is contained in:
2025-05-24 14:50:24 +00:00
parent 6e19e30f87
commit 3d669ed9dd
2 changed files with 363 additions and 303 deletions

View File

@ -6,6 +6,7 @@ import { startTestServer, stopTestServer } from '../../helpers/server.loader.js'
const TEST_PORT = 2525;
let testServer;
const activeSockets = new Set<net.Socket>();
tap.test('prepare server', async () => {
testServer = await startTestServer({ port: TEST_PORT });
@ -19,6 +20,9 @@ tap.test('ERR-07: Exception handling - Invalid commands', async (tools) => {
port: TEST_PORT,
timeout: 30000
});
activeSockets.add(socket);
socket.on('close', () => activeSockets.delete(socket));
socket.on('connect', async () => {
try {
@ -147,6 +151,9 @@ tap.test('ERR-07: Exception handling - Malformed protocol', async (tools) => {
port: TEST_PORT,
timeout: 30000
});
activeSockets.add(socket);
socket.on('close', () => activeSockets.delete(socket));
socket.on('connect', async () => {
try {
@ -224,6 +231,9 @@ tap.test('ERR-07: Exception handling - Recovery after errors', async (tools) =>
port: TEST_PORT,
timeout: 30000
});
activeSockets.add(socket);
socket.on('close', () => activeSockets.delete(socket));
socket.on('connect', async () => {
try {
@ -307,6 +317,16 @@ tap.test('ERR-07: Exception handling - Recovery after errors', async (tools) =>
});
tap.test('cleanup server', async () => {
// Close any remaining sockets
for (const socket of activeSockets) {
if (!socket.destroyed) {
socket.destroy();
}
}
// Wait for all sockets to be fully closed
await new Promise(resolve => setTimeout(resolve, 500));
await stopTestServer(testServer);
});