Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(throttler): silence the stalled client when the spec ends
Yudhi Armyndharis9bcb93b33f6e
diff --git a/test/throttler-redis.e2e-spec.ts b/test/throttler-redis.e2e-spec.tsindex 170158788..cd72bab05 100644--- a/test/throttler-redis.e2e-spec.ts+++ b/test/throttler-redis.e2e-spec.ts@@ -96,29 +96,30 @@ describeWithRedis('the throttler client against a Redis that stops answering', (let blackhole = false;let proxy: net.Server;let storage: RedisThrottlerStorage;+ let client: Redis;let cleaner: Redis;beforeAll(async () => {- proxy = net.createServer(client => {+ proxy = net.createServer(peer => {const upstream = net.connect(REDIS_PORT, REDIS_HOST);- sockets.add(client).add(upstream);- client.on('data', data => {+ sockets.add(peer).add(upstream);+ peer.on('data', data => {if (!blackhole) upstream.write(data);});upstream.on('data', data => {- if (!blackhole) client.write(data);+ if (!blackhole) peer.write(data);});const end = (): void => {- client.destroy();+ peer.destroy();upstream.destroy();};- client.on('close', end);+ peer.on('close', end);upstream.on('close', end);- client.on('error', () => undefined);+ peer.on('error', () => undefined);upstream.on('error', () => undefined);});await new Promise<void>(resolve => proxy.listen(0, '127.0.0.1', resolve));- const client = new Redis({+ client = new Redis({...buildThrottlerRedisOptions(),host: '127.0.0.1',port: (proxy.address() as AddressInfo).port,@@ -132,6 +133,10 @@ describeWithRedis('the throttler client against a Redis that stops answering', (afterAll(async () => {blackhole = false;+ // The client can still report the stall it was put through after this file is done, when the mocked logger is+ // gone and a log line fails the whole run: its errors have nobody left to tell.+ client.removeAllListeners('error');+ client.on('error', () => undefined);const keys = await cleaner.keys(`openwa:throttle:*:${throttler}*`);if (keys.length) await cleaner.del(...keys);cleaner.disconnect();