Skip to content

Commit

Permalink
Merge pull request #5422 from willsoto/fix/kafka-microservice
Browse files Browse the repository at this point in the history
fix(microservice/kafka): properly await disconnect promises
  • Loading branch information
kamilmysliwiec committed Oct 29, 2020
2 parents a13eb17 + 4f96edf commit b36ef52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/microservices/client/client-kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export class ClientKafka extends ClientProxy {
this.responsePatterns.push(this.getResponsePatternName(request));
}

public close(): void {
this.producer && this.producer.disconnect();
this.consumer && this.consumer.disconnect();
public async close(): Promise<void> {
this.producer && (await this.producer.disconnect());
this.consumer && (await this.consumer.disconnect());
this.producer = null;
this.consumer = null;
this.client = null;
Expand Down
8 changes: 4 additions & 4 deletions packages/microservices/test/client/client-kafka.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ describe('ClientKafka', () => {
});

describe('close', () => {
const consumer = { disconnect: sinon.spy() };
const producer = { disconnect: sinon.spy() };
const consumer = { disconnect: sinon.stub().resolves() };
const producer = { disconnect: sinon.stub().resolves() };
beforeEach(() => {
(client as any).consumer = consumer;
(client as any).producer = producer;
});
it('should close server', () => {
client.close();
it('should close server', async () => {
await client.close();

expect(consumer.disconnect.calledOnce).to.be.true;
expect(producer.disconnect.calledOnce).to.be.true;
Expand Down

0 comments on commit b36ef52

Please sign in to comment.