Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AmqpEnvironment implements Environment {
private readonly username: string
private readonly password: string
private readonly container: Container
private connections: Connection[] = []
private readonly connections: Connection[] = []

constructor({ host, port, username, password }: EnvironmentParams) {
this.host = host
Expand Down Expand Up @@ -53,7 +53,7 @@ export class AmqpEnvironment implements Environment {

async close(): Promise<void> {
await this.closeConnections()
this.connections = []
this.connections.length = 0
}

private async closeConnections(): Promise<void> {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/connection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { afterEach, beforeEach, describe, test } from "vitest"
import { use, expect } from "chai"
import chaiAsPromised from "chai-as-promised"
import { createEnvironment, Environment } from "../../src/environment.js"
import { host, port, username, password, numberOfConnections, eventually } from "../support/util.js"

use(chaiAsPromised)

describe("Connection", () => {
let environment: Environment

beforeEach(async () => {
environment = createEnvironment({
host,
port,
username,
password,
})
})

afterEach(async () => {
await environment.close()
})

test("closing the connection", async () => {
const connection = await environment.createConnection()

await connection.close()

await eventually(async () => {
expect(await numberOfConnections()).to.eql(0)
})
})
})