Skip to content

Commit cc3c1c2

Browse files
committed
Add connection_timeout test
1 parent bc51e7f commit cc3c1c2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,21 @@ t('Query and parameters are enumerable if debug is set', async() => {
978978
]
979979
})
980980

981+
t('connect_timeout works', async() => {
982+
const connect_timeout = 0.2
983+
const server = net.createServer()
984+
server.listen()
985+
const sql = postgres({ port: server.address().port, connect_timeout })
986+
const start = Date.now()
987+
let end
988+
await sql`select 1`.catch((e) => {
989+
if (e.code !== 'CONNECT_TIMEOUT')
990+
throw e
991+
end = Date.now()
992+
})
993+
return [connect_timeout, Math.floor((end - start) / 100) / 10]
994+
})
995+
981996
t('connect_timeout throws proper error', async() => [
982997
'CONNECT_TIMEOUT',
983998
await postgres({

0 commit comments

Comments
 (0)