From 10e9e2c0084a72b39d27f202a6b146008446fa99 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 15 Dec 2025 09:41:31 -0500 Subject: [PATCH] ci: Improve Redis client disconnection handling in integration tests - Updated the afterAll cleanup logic in integration tests for GenerationJobManager, RedisEventTransport, and RedisJobStore to use `quit()` for graceful disconnection of the Redis client. - Added fallback to `disconnect()` if `quit()` fails, enhancing robustness in resource management during test teardown. - Improved comments for clarity on the disconnection process and error handling. --- .../GenerationJobManager.stream_integration.spec.ts | 12 +++++++++--- .../RedisEventTransport.stream_integration.spec.ts | 12 +++++++++--- .../RedisJobStore.stream_integration.spec.ts | 12 +++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/api/src/stream/__tests__/GenerationJobManager.stream_integration.spec.ts b/packages/api/src/stream/__tests__/GenerationJobManager.stream_integration.spec.ts index cd7a5d4864..c593d3d15a 100644 --- a/packages/api/src/stream/__tests__/GenerationJobManager.stream_integration.spec.ts +++ b/packages/api/src/stream/__tests__/GenerationJobManager.stream_integration.spec.ts @@ -45,11 +45,17 @@ describe('GenerationJobManager Integration Tests', () => { }); afterAll(async () => { - if (ioredisClient && 'disconnect' in ioredisClient) { + if (ioredisClient) { try { - ioredisClient.disconnect(); + // Use quit() to gracefully close - waits for pending commands + await ioredisClient.quit(); } catch { - // Ignore disconnect errors + // Fall back to disconnect if quit fails + try { + ioredisClient.disconnect(); + } catch { + // Ignore + } } } process.env = originalEnv; diff --git a/packages/api/src/stream/__tests__/RedisEventTransport.stream_integration.spec.ts b/packages/api/src/stream/__tests__/RedisEventTransport.stream_integration.spec.ts index ad42573a5d..b70e53012e 100644 --- a/packages/api/src/stream/__tests__/RedisEventTransport.stream_integration.spec.ts +++ b/packages/api/src/stream/__tests__/RedisEventTransport.stream_integration.spec.ts @@ -29,11 +29,17 @@ describe('RedisEventTransport Integration Tests', () => { }); afterAll(async () => { - if (ioredisClient && 'disconnect' in ioredisClient) { + if (ioredisClient) { try { - ioredisClient.disconnect(); + // Use quit() to gracefully close - waits for pending commands + await ioredisClient.quit(); } catch { - // Ignore + // Fall back to disconnect if quit fails + try { + ioredisClient.disconnect(); + } catch { + // Ignore + } } } process.env = originalEnv; diff --git a/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts b/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts index d57fd1e08d..95ea15dbb3 100644 --- a/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts +++ b/packages/api/src/stream/__tests__/RedisJobStore.stream_integration.spec.ts @@ -57,11 +57,17 @@ describe('RedisJobStore Integration Tests', () => { }); afterAll(async () => { - if (ioredisClient && 'disconnect' in ioredisClient) { + if (ioredisClient) { try { - ioredisClient.disconnect(); + // Use quit() to gracefully close - waits for pending commands + await ioredisClient.quit(); } catch { - // Ignore disconnect errors + // Fall back to disconnect if quit fails + try { + ioredisClient.disconnect(); + } catch { + // Ignore + } } } process.env = originalEnv;