refactor: reconnection timeout behavior in OAuthReconnectionManager and OAuthReconnectionTracker

- Implement tests to verify reconnection timeout handling, including tracking of reconnection states and cleanup of timed-out entries.
- Enhance existing methods in OAuthReconnectionManager and OAuthReconnectionTracker to support timeout checks and cleanup logic.
- Ensure proper handling of multiple servers with different timeout periods and edge cases for active states.
This commit is contained in:
Danny Avila 2025-09-21 08:30:55 -04:00
parent cbfbdeb787
commit c5c4011ce8
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
4 changed files with 524 additions and 8 deletions

View file

@ -12,18 +12,39 @@ export class OAuthReconnectionTracker {
return this.failed.get(userId)?.has(serverName) ?? false;
}
/** Check if server is in the active set (original simple check) */
public isActive(userId: string, serverName: string): boolean {
const key = `${userId}:${serverName}`;
const startTime = this.activeTimestamps.get(key);
return this.active.get(userId)?.has(serverName) ?? false;
}
// Check if reconnection has timed out
if (startTime && Date.now() - startTime > this.RECONNECTION_TIMEOUT_MS) {
// Auto-cleanup timed out reconnection
this.removeActive(userId, serverName);
/** Check if server is still reconnecting (considers timeout) */
public isStillReconnecting(userId: string, serverName: string): boolean {
if (!this.isActive(userId, serverName)) {
return false;
}
return this.active.get(userId)?.has(serverName) ?? false;
const key = `${userId}:${serverName}`;
const startTime = this.activeTimestamps.get(key);
// If there's a timestamp and it has timed out, it's not still reconnecting
if (startTime && Date.now() - startTime > this.RECONNECTION_TIMEOUT_MS) {
return false;
}
return true;
}
/** Clean up server if it has timed out - returns true if cleanup was performed */
public cleanupIfTimedOut(userId: string, serverName: string): boolean {
const key = `${userId}:${serverName}`;
const startTime = this.activeTimestamps.get(key);
if (startTime && Date.now() - startTime > this.RECONNECTION_TIMEOUT_MS) {
this.removeActive(userId, serverName);
return true;
}
return false;
}
public setFailed(userId: string, serverName: string): void {