1
- /* eslint no-console: 0 */
2
-
3
1
const { exec } = require ( './bootstrap.js' )
4
2
5
3
const { t, nt, ot } = require ( './test.js' ) // eslint-disable-line
@@ -666,18 +664,19 @@ t('listen and notify with upper case', async() => {
666
664
667
665
t ( 'listen reconnects' , { timeout : 2 } , async ( ) => {
668
666
const sql = postgres ( options )
669
- , xs = [ ]
667
+ , resolvers = { }
668
+ , a = new Promise ( r => resolvers . a = r )
669
+ , b = new Promise ( r => resolvers . b = r )
670
670
671
- const { state : { pid } } = await sql . listen ( 'test' , x => xs . push ( x ) )
672
- await delay ( 200 )
671
+ const { state : { pid } } = await sql . listen ( 'test' , x => x in resolvers && resolvers [ x ] ( ) )
673
672
await sql . notify ( 'test' , 'a' )
674
- await sql `select pg_terminate_backend(${ pid } ::int)`
675
- await delay ( 200 )
673
+ await a
674
+ await sql `select pg_terminate_backend(${ pid } )`
675
+ await delay ( 50 )
676
676
await sql . notify ( 'test' , 'b' )
677
- await delay ( 200 )
677
+ await b
678
678
sql . end ( )
679
-
680
- return [ 'ab' , xs . join ( '' ) ]
679
+ return [ true , true ]
681
680
} )
682
681
683
682
@@ -687,7 +686,7 @@ t('listen reconnects after connection error', { timeout: 3 }, async() => {
687
686
688
687
const { state : { pid } } = await sql . listen ( 'test' , x => xs . push ( x ) )
689
688
await sql . notify ( 'test' , 'a' )
690
- await sql `select pg_terminate_backend(${ pid } ::int )`
689
+ await sql `select pg_terminate_backend(${ pid } )`
691
690
await delay ( 1000 )
692
691
693
692
await sql . notify ( 'test' , 'b' )
@@ -704,7 +703,7 @@ t('listen result reports correct connection state after reconnection', async() =
704
703
const result = await sql . listen ( 'test' , x => xs . push ( x ) )
705
704
const initialPid = result . state . pid
706
705
await sql . notify ( 'test' , 'a' )
707
- await sql `select pg_terminate_backend(${ initialPid } ::int )`
706
+ await sql `select pg_terminate_backend(${ initialPid } )`
708
707
await delay ( 50 )
709
708
sql . end ( )
710
709
@@ -852,7 +851,7 @@ t('Connection errors are caught using begin()', {
852
851
} , async ( ) => {
853
852
let error
854
853
try {
855
- const sql = postgres ( { host : 'wat ' , port : 1337 } )
854
+ const sql = postgres ( { host : 'localhost ' , port : 1 } )
856
855
857
856
await sql . begin ( async ( sql ) => {
858
857
await sql `insert into test (label, value) values (${ 1 } , ${ 2 } )`
@@ -863,8 +862,8 @@ t('Connection errors are caught using begin()', {
863
862
864
863
return [
865
864
true ,
866
- error . code === 'ENOTFOUND ' ||
867
- error . message === 'failed to lookup address information: nodename nor servname provided, or not known '
865
+ error . code === 'ECONNREFUSED ' ||
866
+ error . message === 'Connection refused (os error 61) '
868
867
]
869
868
} )
870
869
@@ -1016,8 +1015,8 @@ t('throws correct error when authentication fails', async() => {
1016
1015
1017
1016
t ( 'notice works' , async ( ) => {
1018
1017
let notice
1019
- const log = console . log
1020
- console . log = function ( x ) {
1018
+ const log = console . log // eslint-disable-line
1019
+ console . log = function ( x ) { // eslint-disable-line
1021
1020
notice = x
1022
1021
}
1023
1022
@@ -1026,7 +1025,7 @@ t('notice works', async() => {
1026
1025
await sql `create table if not exists users()`
1027
1026
await sql `create table if not exists users()`
1028
1027
1029
- console . log = log
1028
+ console . log = log // eslint-disable-line
1030
1029
1031
1030
return [ 'NOTICE' , notice . severity ]
1032
1031
} )
@@ -1252,7 +1251,7 @@ t('Transform columns from', async() => {
1252
1251
t ( 'Unix socket' , async ( ) => {
1253
1252
const sql = postgres ( {
1254
1253
...options ,
1255
- host : '/tmp'
1254
+ host : process . env . PGSOCKET || '/tmp' // eslint-disable-line
1256
1255
} )
1257
1256
1258
1257
return [ 1 , ( await sql `select 1 as x` ) [ 0 ] . x ]
@@ -1378,7 +1377,7 @@ t('requests works after single connect_timeout', async() => {
1378
1377
const sql = postgres ( {
1379
1378
...options ,
1380
1379
...login_scram ,
1381
- connect_timeout : { valueOf ( ) { return first ? ( first = false , 0.001 ) : 1 } }
1380
+ connect_timeout : { valueOf ( ) { return first ? ( first = false , 0.0001 ) : 1 } }
1382
1381
} )
1383
1382
1384
1383
return [
@@ -1538,19 +1537,22 @@ t('Multiple hosts', {
1538
1537
, sql = postgres ( 'postgres://localhost:5432,localhost:5433' , { idle_timeout, max : 1 } )
1539
1538
, result = [ ]
1540
1539
1540
+ const id1 = ( await s1 `select system_identifier as x from pg_control_system()` ) [ 0 ] . x
1541
+ const id2 = ( await s2 `select system_identifier as x from pg_control_system()` ) [ 0 ] . x
1542
+
1541
1543
const x1 = await sql `select 1`
1542
- result . push ( ( await sql `select setting as x from pg_settings where name = 'port' ` ) [ 0 ] . x )
1544
+ result . push ( ( await sql `select system_identifier as x from pg_control_system() ` ) [ 0 ] . x )
1543
1545
await s1 `select pg_terminate_backend(${ x1 . state . pid } ::int)`
1544
1546
await delay ( 100 )
1545
1547
1546
1548
const x2 = await sql `select 1`
1547
- result . push ( ( await sql `select setting as x from pg_settings where name = 'port' ` ) [ 0 ] . x )
1549
+ result . push ( ( await sql `select system_identifier as x from pg_control_system() ` ) [ 0 ] . x )
1548
1550
await s2 `select pg_terminate_backend(${ x2 . state . pid } ::int)`
1549
1551
await delay ( 100 )
1550
1552
1551
- result . push ( ( await sql `select setting as x from pg_settings where name = 'port' ` ) [ 0 ] . x )
1553
+ result . push ( ( await sql `select system_identifier as x from pg_control_system() ` ) [ 0 ] . x )
1552
1554
1553
- return [ '5432,5433,5432' , result . join ( ',' ) ]
1555
+ return [ [ id1 , id2 , id1 ] . join ( ',' ) , result . join ( ',' ) ]
1554
1556
} )
1555
1557
1556
1558
t ( 'Escaping supports schemas and tables' , async ( ) => {
@@ -1762,9 +1764,9 @@ t('Cancel running query works', async() => {
1762
1764
1763
1765
t ( 'Cancel piped query works' , { timeout : 1 } , async ( ) => {
1764
1766
await sql `select 1`
1765
- const last = sql `select pg_sleep(0.2 )` . execute ( )
1767
+ const last = sql `select pg_sleep(0.3 )` . execute ( )
1766
1768
const query = sql `select pg_sleep(2) as dig`
1767
- setTimeout ( ( ) => query . cancel ( ) , 100 )
1769
+ setTimeout ( ( ) => query . cancel ( ) , 10 )
1768
1770
const error = await query . catch ( x => x )
1769
1771
await last
1770
1772
return [ '57014' , error . code ]
@@ -1773,7 +1775,7 @@ t('Cancel piped query works', { timeout: 1 }, async() => {
1773
1775
t ( 'Cancel queued query works' , async ( ) => {
1774
1776
const tx = sql . begin ( sql => sql `select pg_sleep(0.2) as hej, 'hejsa'` )
1775
1777
const query = sql `select pg_sleep(2) as nej`
1776
- setTimeout ( ( ) => query . cancel ( ) , 50 )
1778
+ setTimeout ( ( ) => query . cancel ( ) , 100 )
1777
1779
const error = await query . catch ( x => x )
1778
1780
await tx
1779
1781
return [ '57014' , error . code ]
@@ -1942,7 +1944,7 @@ t('Prevent premature end of connection in transaction', async() => {
1942
1944
]
1943
1945
} )
1944
1946
1945
- t ( 'Ensure reconnect after max_lifetime with transactions' , { timeout : 5000 } , async ( ) => {
1947
+ t ( 'Ensure reconnect after max_lifetime with transactions' , { timeout : 5 } , async ( ) => {
1946
1948
const sql = postgres ( {
1947
1949
max_lifetime : 0.01 ,
1948
1950
idle_timeout,
0 commit comments