Skip to content

Commit 31ca683

Browse files
committed
Fix test flake on old node
1 parent da49303 commit 31ca683

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/pg/test/integration/client/connection-timeout-tests.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const options = {
1313
database: 'existing',
1414
}
1515

16-
const serverWithConnectionTimeout = (timeout, callback) => {
16+
const serverWithConnectionTimeout = (port, timeout, callback) => {
1717
const sockets = new Set()
1818

1919
const server = net.createServer((socket) => {
@@ -47,11 +47,11 @@ const serverWithConnectionTimeout = (timeout, callback) => {
4747
}
4848
}
4949

50-
server.listen(options.port, options.host, () => callback(closeServer))
50+
server.listen(port, options.host, () => callback(closeServer))
5151
}
5252

5353
suite.test('successful connection', (done) => {
54-
serverWithConnectionTimeout(0, (closeServer) => {
54+
serverWithConnectionTimeout(options.port, 0, (closeServer) => {
5555
const timeoutId = setTimeout(() => {
5656
throw new Error('Client should have connected successfully but it did not.')
5757
}, 3000)
@@ -67,12 +67,13 @@ suite.test('successful connection', (done) => {
6767
})
6868

6969
suite.test('expired connection timeout', (done) => {
70-
serverWithConnectionTimeout(options.connectionTimeoutMillis * 2, (closeServer) => {
70+
const opts = { ...options, port: 54322 }
71+
serverWithConnectionTimeout(opts.port, opts.connectionTimeoutMillis * 2, (closeServer) => {
7172
const timeoutId = setTimeout(() => {
7273
throw new Error('Client should have emitted an error but it did not.')
7374
}, 3000)
7475

75-
const client = new helper.Client(options)
76+
const client = new helper.Client(opts)
7677
client
7778
.connect()
7879
.then(() => client.end())

0 commit comments

Comments
 (0)