From 0371f491023ec342140a17cf7e22884a43eaabe7 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Wed, 27 Sep 2023 23:33:18 +0300 Subject: [PATCH] Use silent channel --- .../test/publishers/AmqpPermissionPublisher.spec.ts | 9 ++++++--- packages/amqp/test/utils/channelUtils.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 packages/amqp/test/utils/channelUtils.ts diff --git a/packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts b/packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts index 14493aab..50bdf857 100644 --- a/packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts +++ b/packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts @@ -11,6 +11,7 @@ import { PERMISSIONS_MESSAGE_SCHEMA } from '../consumers/userConsumerSchemas' import { FakeConsumer } from '../fakes/FakeConsumer' import { FakeConsumerErrorResolver } from '../fakes/FakeConsumerErrorResolver' import { FakeLogger } from '../fakes/FakeLogger' +import { createSilentChannel } from '../utils/channelUtils' import { TEST_AMQP_CONFIG } from '../utils/testAmqpConfig' import type { Dependencies } from '../utils/testContext' import { registerDependencies, SINGLETON_CONFIG } from '../utils/testContext' @@ -188,8 +189,10 @@ describe('PermissionPublisher', () => { await diContainer.cradle.amqpConnectionManager.init() let receivedMessage: PERMISSIONS_MESSAGE_TYPE | null = null - channel = await diContainer.cradle.amqpConnectionManager.getConnectionSync()!.createChannel() - await channel.consume(AmqpPermissionPublisher.QUEUE_NAME, (message) => { + const consumerChannel = await createSilentChannel( + diContainer.cradle.amqpConnectionManager.getConnectionSync()!, + ) + await consumerChannel.consume(AmqpPermissionPublisher.QUEUE_NAME, (message) => { if (message === null) { return } @@ -215,7 +218,7 @@ describe('PermissionPublisher', () => { await permissionPublisher.close() try { - await channel.close() + await consumerChannel.close() } catch { // it's ok } diff --git a/packages/amqp/test/utils/channelUtils.ts b/packages/amqp/test/utils/channelUtils.ts new file mode 100644 index 00000000..14f93408 --- /dev/null +++ b/packages/amqp/test/utils/channelUtils.ts @@ -0,0 +1,13 @@ +import type { Connection } from 'amqplib' + +export async function createSilentChannel(connection: Connection) { + const channel = await connection.createChannel() + channel.on('close', () => { + // consume event + }) + channel.on('error', (err) => { + // consume event + }) + + return channel +}