fix(tests): fix tests
This commit is contained in:
@ -30,10 +30,27 @@ tap.test('cleanup queue bug - verify queue processing handles more than batch si
|
||||
const mockConnections: any[] = [];
|
||||
|
||||
for (let i = 0; i < 150; i++) {
|
||||
// Create mock socket objects with necessary methods
|
||||
const mockIncoming = {
|
||||
destroyed: true,
|
||||
writable: false,
|
||||
remoteAddress: '127.0.0.1',
|
||||
removeAllListeners: () => {},
|
||||
destroy: () => {},
|
||||
end: () => {}
|
||||
};
|
||||
|
||||
const mockOutgoing = {
|
||||
destroyed: true,
|
||||
writable: false,
|
||||
destroy: () => {},
|
||||
end: () => {}
|
||||
};
|
||||
|
||||
const mockRecord = {
|
||||
id: `mock-${i}`,
|
||||
incoming: { destroyed: true, remoteAddress: '127.0.0.1' },
|
||||
outgoing: { destroyed: true },
|
||||
incoming: mockIncoming,
|
||||
outgoing: mockOutgoing,
|
||||
connectionClosed: false,
|
||||
incomingStartTime: Date.now(),
|
||||
lastActivity: Date.now(),
|
||||
@ -66,9 +83,17 @@ tap.test('cleanup queue bug - verify queue processing handles more than batch si
|
||||
// Wait for cleanup to complete
|
||||
console.log('\n--- Waiting for cleanup batches to process ---');
|
||||
|
||||
// The first batch should process immediately (100 connections)
|
||||
// Then additional batches should be scheduled
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
// The cleanup happens in batches, wait for all to complete
|
||||
let waitTime = 0;
|
||||
while (cm.getConnectionCount() > 0 || cm.cleanupQueue.size > 0) {
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
waitTime += 100;
|
||||
if (waitTime > 5000) {
|
||||
console.log('Timeout waiting for cleanup to complete');
|
||||
break;
|
||||
}
|
||||
}
|
||||
console.log(`Cleanup completed in ${waitTime}ms`);
|
||||
|
||||
// Check final state
|
||||
const finalCount = cm.getConnectionCount();
|
||||
@ -85,6 +110,7 @@ tap.test('cleanup queue bug - verify queue processing handles more than batch si
|
||||
expect(stats.incoming.test_cleanup).toEqual(150);
|
||||
|
||||
// Cleanup
|
||||
console.log('\n--- Stopping proxy ---');
|
||||
await proxy.stop();
|
||||
|
||||
console.log('\n✓ Test complete: Cleanup queue now correctly processes all connections');
|
||||
|
Reference in New Issue
Block a user