Skip to content

Commit b7c9869

Browse files
committed
tests
1 parent c314414 commit b7c9869

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

test/e2e/environment.test.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { afterEach, beforeEach, describe, expect, test } from "vitest"
22
import { createEnvironment, Environment } from "../../src/environment.js"
3-
import { host, port, username, password, numberOfConnections, eventually } from "../support/util.js"
3+
import {
4+
host,
5+
port,
6+
username,
7+
password,
8+
numberOfConnections,
9+
eventually,
10+
closeAllConnections,
11+
wait,
12+
} from "../support/util.js"
413

514
describe("Environment", () => {
615
let environment: Environment
@@ -26,9 +35,42 @@ describe("Environment", () => {
2635
})
2736
})
2837

29-
test("create a connection with reconnect true", async () => {
38+
test("a connection with reconnect false does not reconnect", async () => {
39+
await environment.createConnection({ reconnect: false })
40+
41+
await closeAllConnections()
42+
await wait(2000)
43+
44+
expect(await numberOfConnections()).to.eql(0)
45+
})
46+
47+
test("a connection with reconnect true reconnects", async () => {
3048
await environment.createConnection({ reconnect: true })
3149

50+
await closeAllConnections()
51+
52+
await eventually(async () => {
53+
expect(await numberOfConnections()).to.eql(1)
54+
})
55+
})
56+
57+
test("a connection reconnects by default", async () => {
58+
await environment.createConnection()
59+
60+
await closeAllConnections()
61+
62+
await eventually(async () => {
63+
expect(await numberOfConnections()).to.eql(1)
64+
})
65+
})
66+
67+
test("a connection with reconnect set to number retries after number ms", async () => {
68+
await environment.createConnection({ reconnect: 2000, initialReconnectDelay: 2000 })
69+
70+
await closeAllConnections()
71+
await wait(1900)
72+
73+
expect(await numberOfConnections()).to.eql(0)
3274
await eventually(async () => {
3375
expect(await numberOfConnections()).to.eql(1)
3476
})

test/unit/rhea/connection.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, test } from "vitest"
22
import { host, port, username, password, numberOfConnections, eventually } from "../../support/util.js"
33
import { Connection, Container, create_container } from "rhea"
44
import { closeConnection, openConnection, openManagement } from "../../support/rhea_utils.js"
5-
import { isReconnectionParamsDetails } from "../../../src/connection.js"
65

76
describe("Rhea connections", () => {
87
let container: Container
@@ -41,17 +40,4 @@ describe("Rhea connections", () => {
4140
await openManagement(connection)
4241
}, 4000)
4342
})
44-
45-
test("is reconnection param detail", () => {
46-
expect(isReconnectionParamsDetails(true)).to.eql(false)
47-
expect(isReconnectionParamsDetails(false)).to.eql(false)
48-
expect(isReconnectionParamsDetails(123)).to.eql(false)
49-
expect(
50-
isReconnectionParamsDetails({
51-
initialReconnectDelay: 1,
52-
maxReconnectDelay: 1,
53-
reconnectLimit: 1,
54-
})
55-
).to.eql(true)
56-
})
5743
})

0 commit comments

Comments
 (0)