Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(microservices): fix usage noassert flag in rabbitmq #13313

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/microservices/client/client-rmq.ts
Expand Up @@ -187,7 +187,7 @@ export class ClientRMQ extends ClientProxy {
this.getOptionsProp(this.options, 'isGlobalPrefetchCount') ||
RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT;

if (!this.queueOptions.noAssert) {
if (!this.noAssert) {
await channel.assertQueue(this.queue, this.queueOptions);
}
await channel.prefetch(prefetchCount, isGlobalPrefetchCount);
Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/server/server-rmq.ts
Expand Up @@ -145,7 +145,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
}

public async setupChannel(channel: any, callback: Function) {
if (!this.queueOptions.noAssert) {
if (!this.noAssert) {
await channel.assertQueue(this.queue, this.queueOptions);
}
await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);
Expand Down
8 changes: 8 additions & 0 deletions packages/microservices/test/client/client-rmq.spec.ts
Expand Up @@ -119,6 +119,7 @@ describe('ClientRMQ', function () {
const prefetchCount = 10;

let consumeStub: sinon.SinonStub;
let noAssertStub: sinon.SinonStub;
let channel: any = {};

beforeEach(() => {
Expand All @@ -131,14 +132,21 @@ describe('ClientRMQ', function () {
prefetch: sinon.spy(),
};
consumeStub = sinon.stub(client, 'consumeChannel').callsFake(() => null);
noAssertStub = sinon.stub(client as any, 'noAssert').value(false);
});
afterEach(() => {
consumeStub.restore();
noAssertStub.restore();
});
it('should call "assertQueue" with queue and queue options', async () => {
await client.setupChannel(channel, () => null);
expect(channel.assertQueue.calledWith(queue, queueOptions)).to.be.true;
});
it('should not call "assertQueue" when "noAssert" flag is true', async () => {
sinon.stub(client as any, 'noAssert').value(true);
await client.setupChannel(channel, () => null);
expect(channel.assertQueue.notCalled).to.be.true;
});
it('should call "prefetch" with prefetchCount and "isGlobalPrefetchCount"', async () => {
await client.setupChannel(channel, () => null);
expect(channel.prefetch.calledWith(prefetchCount, isGlobalPrefetchCount))
Expand Down
10 changes: 10 additions & 0 deletions packages/microservices/test/server/server-rmq.spec.ts
Expand Up @@ -182,6 +182,7 @@ describe('ServerRMQ', () => {
const isGlobalPrefetchCount = true;
const prefetchCount = 10;

let noAssertStub: sinon.SinonStub;
let channel: any = {};

beforeEach(() => {
Expand All @@ -195,11 +196,20 @@ describe('ServerRMQ', () => {
prefetch: sinon.spy(),
consume: sinon.spy(),
};
noAssertStub = sinon.stub(server as any, 'noAssert').value(false);
});
afterEach(() => {
noAssertStub.restore();
});
it('should call "assertQueue" with queue and queue options', async () => {
await server.setupChannel(channel, () => null);
expect(channel.assertQueue.calledWith(queue, queueOptions)).to.be.true;
});
it('should not call "assertQueue" when "noAssert" flag is true', async () => {
sinon.stub(server as any, 'noAssert').value(true);
await server.setupChannel(channel, () => null);
expect(channel.assertQueue.notCalled).to.be.true;
});
it('should call "prefetch" with prefetchCount and "isGlobalPrefetchCount"', async () => {
await server.setupChannel(channel, () => null);
expect(channel.prefetch.calledWith(prefetchCount, isGlobalPrefetchCount))
Expand Down