Skip to content

Commit

Permalink
Use silent channel
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Sep 27, 2023
1 parent ab9461c commit 0371f49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
Expand All @@ -215,7 +218,7 @@ describe('PermissionPublisher', () => {

await permissionPublisher.close()
try {
await channel.close()
await consumerChannel.close()
} catch {
// it's ok
}
Expand Down
13 changes: 13 additions & 0 deletions packages/amqp/test/utils/channelUtils.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 0371f49

Please sign in to comment.