1- /* eslint no-console: 0 */
2-
31const { exec } = require ( './bootstrap.js' )
42
53const { t, nt, ot } = require ( './test.js' ) // eslint-disable-line
@@ -666,18 +664,19 @@ t('listen and notify with upper case', async() => {
666664
667665t ( 'listen reconnects' , { timeout : 2 } , async ( ) => {
668666 const sql = postgres ( options )
669- , xs = [ ]
667+ , resolvers = { }
668+ , a = new Promise ( r => resolvers . a = r )
669+ , b = new Promise ( r => resolvers . b = r )
670670
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 ] ( ) )
673672 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 )
676676 await sql . notify ( 'test' , 'b' )
677- await delay ( 200 )
677+ await b
678678 sql . end ( )
679-
680- return [ 'ab' , xs . join ( '' ) ]
679+ return [ true , true ]
681680} )
682681
683682
@@ -687,7 +686,7 @@ t('listen reconnects after connection error', { timeout: 3 }, async() => {
687686
688687 const { state : { pid } } = await sql . listen ( 'test' , x => xs . push ( x ) )
689688 await sql . notify ( 'test' , 'a' )
690- await sql `select pg_terminate_backend(${ pid } ::int )`
689+ await sql `select pg_terminate_backend(${ pid } )`
691690 await delay ( 1000 )
692691
693692 await sql . notify ( 'test' , 'b' )
@@ -704,7 +703,7 @@ t('listen result reports correct connection state after reconnection', async() =
704703 const result = await sql . listen ( 'test' , x => xs . push ( x ) )
705704 const initialPid = result . state . pid
706705 await sql . notify ( 'test' , 'a' )
707- await sql `select pg_terminate_backend(${ initialPid } ::int )`
706+ await sql `select pg_terminate_backend(${ initialPid } )`
708707 await delay ( 50 )
709708 sql . end ( )
710709
@@ -852,7 +851,7 @@ t('Connection errors are caught using begin()', {
852851} , async ( ) => {
853852 let error
854853 try {
855- const sql = postgres ( { host : 'wat ' , port : 1337 } )
854+ const sql = postgres ( { host : 'localhost ' , port : 1 } )
856855
857856 await sql . begin ( async ( sql ) => {
858857 await sql `insert into test (label, value) values (${ 1 } , ${ 2 } )`
@@ -863,8 +862,8 @@ t('Connection errors are caught using begin()', {
863862
864863 return [
865864 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) '
868867 ]
869868} )
870869
@@ -1016,8 +1015,8 @@ t('throws correct error when authentication fails', async() => {
10161015
10171016t ( 'notice works' , async ( ) => {
10181017 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
10211020 notice = x
10221021 }
10231022
@@ -1026,7 +1025,7 @@ t('notice works', async() => {
10261025 await sql `create table if not exists users()`
10271026 await sql `create table if not exists users()`
10281027
1029- console . log = log
1028+ console . log = log // eslint-disable-line
10301029
10311030 return [ 'NOTICE' , notice . severity ]
10321031} )
@@ -1252,7 +1251,7 @@ t('Transform columns from', async() => {
12521251t ( 'Unix socket' , async ( ) => {
12531252 const sql = postgres ( {
12541253 ...options ,
1255- host : '/tmp'
1254+ host : process . env . PGSOCKET || '/tmp' // eslint-disable-line
12561255 } )
12571256
12581257 return [ 1 , ( await sql `select 1 as x` ) [ 0 ] . x ]
@@ -1378,7 +1377,7 @@ t('requests works after single connect_timeout', async() => {
13781377 const sql = postgres ( {
13791378 ...options ,
13801379 ...login_scram ,
1381- connect_timeout : { valueOf ( ) { return first ? ( first = false , 0.001 ) : 1 } }
1380+ connect_timeout : { valueOf ( ) { return first ? ( first = false , 0.0001 ) : 1 } }
13821381 } )
13831382
13841383 return [
@@ -1538,19 +1537,22 @@ t('Multiple hosts', {
15381537 , sql = postgres ( 'postgres://localhost:5432,localhost:5433' , { idle_timeout, max : 1 } )
15391538 , result = [ ]
15401539
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+
15411543 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 )
15431545 await s1 `select pg_terminate_backend(${ x1 . state . pid } ::int)`
15441546 await delay ( 100 )
15451547
15461548 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 )
15481550 await s2 `select pg_terminate_backend(${ x2 . state . pid } ::int)`
15491551 await delay ( 100 )
15501552
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 )
15521554
1553- return [ '5432,5433,5432' , result . join ( ',' ) ]
1555+ return [ [ id1 , id2 , id1 ] . join ( ',' ) , result . join ( ',' ) ]
15541556} )
15551557
15561558t ( 'Escaping supports schemas and tables' , async ( ) => {
@@ -1762,9 +1764,9 @@ t('Cancel running query works', async() => {
17621764
17631765t ( 'Cancel piped query works' , { timeout : 1 } , async ( ) => {
17641766 await sql `select 1`
1765- const last = sql `select pg_sleep(0.2 )` . execute ( )
1767+ const last = sql `select pg_sleep(0.3 )` . execute ( )
17661768 const query = sql `select pg_sleep(2) as dig`
1767- setTimeout ( ( ) => query . cancel ( ) , 100 )
1769+ setTimeout ( ( ) => query . cancel ( ) , 10 )
17681770 const error = await query . catch ( x => x )
17691771 await last
17701772 return [ '57014' , error . code ]
@@ -1773,7 +1775,7 @@ t('Cancel piped query works', { timeout: 1 }, async() => {
17731775t ( 'Cancel queued query works' , async ( ) => {
17741776 const tx = sql . begin ( sql => sql `select pg_sleep(0.2) as hej, 'hejsa'` )
17751777 const query = sql `select pg_sleep(2) as nej`
1776- setTimeout ( ( ) => query . cancel ( ) , 50 )
1778+ setTimeout ( ( ) => query . cancel ( ) , 100 )
17771779 const error = await query . catch ( x => x )
17781780 await tx
17791781 return [ '57014' , error . code ]
@@ -1942,7 +1944,7 @@ t('Prevent premature end of connection in transaction', async() => {
19421944 ]
19431945} )
19441946
1945- t ( 'Ensure reconnect after max_lifetime with transactions' , { timeout : 5000 } , async ( ) => {
1947+ t ( 'Ensure reconnect after max_lifetime with transactions' , { timeout : 5 } , async ( ) => {
19461948 const sql = postgres ( {
19471949 max_lifetime : 0.01 ,
19481950 idle_timeout,
0 commit comments