Skip to content

Commit

Permalink
added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoDiTosto committed May 3, 2023
1 parent e44599a commit 62f04e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export class Connection {
return res.ok
}

public getConsumersNumber() {
return this.consumers.length
}

public send(cmd: Request): Promise<void> {
return new Promise((res, rej) => {
const body = cmd.toBuffer()
Expand Down
10 changes: 9 additions & 1 deletion test/e2e/close_consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Connection, connect } from "../../src"
import { Message } from "../../src/producer"
import { Offset } from "../../src/requests/subscribe_request"
import { Rabbit } from "../support/rabbit"
import { eventually } from "../support/util"
import { eventually, expectToThrowAsync } from "../support/util"

describe("close consumer", () => {
const rabbit = new Rabbit()
Expand Down Expand Up @@ -40,5 +40,13 @@ describe("close consumer", () => {
const response = await connection.closeConsumer(consumer.consumerId)

await eventually(() => expect(response).eql(true))
await eventually(() => expect(connection.getConsumersNumber()).eql(0))
}).timeout(10000)

it("closing a non-existing consumer should rise an error", async () => {
const nonExistingConsumerId = 123456
await connection.declarePublisher({ stream: testStreamName })

await expectToThrowAsync(() => connection.closeConsumer(nonExistingConsumerId), Error)
}).timeout(10000)
})

0 comments on commit 62f04e7

Please sign in to comment.