11import { afterEach , beforeEach , describe , expect , test } from "vitest"
22import { 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
514describe ( "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 } )
0 commit comments