Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(events): answer subscriptions while the Redis fake stalls

Yudhi Armyndharise7140f9debd4
diff --git a/src/modules/events/redis-io.adapter.stall.spec.ts b/src/modules/events/redis-io.adapter.stall.spec.ts
index 422d1be18..455b48cbe 100644
--- a/src/modules/events/redis-io.adapter.stall.spec.ts
+++ b/src/modules/events/redis-io.adapter.stall.spec.ts
@@ -26,7 +26,10 @@ class FakeRedis {
pending = Buffer.concat([pending, chunk]);
for (const command of FakeRedis.takeCommands(pending, rest => (pending = rest))) {
if (command[0].toUpperCase() === 'PUBLISH') this.published.push(command[2]);
- if (!this.silent) socket.write(FakeRedis.reply(command));
+ // A stalled peer answers nothing the publisher or its reconnect asks. Subscriptions are exempt: the adapter
+ // issues them without a handler, when a namespace is first used, and a SUBSCRIBE that no reply ever
+ // settles is rejected as an unhandled rejection when the client is closed, which ends a Jest worker.
+ if (!this.silent || /^p?subscribe$/i.test(command[0])) socket.write(FakeRedis.reply(command));
}
});
});