Skip to content

Commit db26c62

Browse files
committed
Test more PostgreSQL and Node versions in CI
1 parent 5862a7d commit db26c62

File tree

10 files changed

+42
-28
lines changed

10 files changed

+42
-28
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ on: [push, pull_request]
44

55
jobs:
66
test:
7-
name: Test Node v${{ matrix.node }}
7+
name: Node v${{ matrix.node }} on PostgreSQL v${{ matrix.postgres }}
88
strategy:
99
fail-fast: false
1010
matrix:
11-
node: ['12', '14', '16', '17', '18']
11+
node: ['12', '14', '16', '18', '20']
12+
postgres: ['12', '13', '14', '15']
1213
runs-on: ubuntu-latest
1314
services:
1415
postgres:
15-
image: postgres
16+
image: postgres:${{ matrix.postgres }}
1617
env:
1718
POSTGRES_USER: postgres
1819
POSTGRES_HOST_AUTH_METHOD: trust
@@ -27,15 +28,22 @@ jobs:
2728
- uses: actions/checkout@v3
2829
- run: |
2930
date
30-
sudo cp ./tests/pg_hba.conf /etc/postgresql/14/main/pg_hba.conf
31-
sudo sed -i 's/.*wal_level.*/wal_level = logical/' /etc/postgresql/14/main/postgresql.conf
32-
sudo sed -i 's/.*ssl = .*/ssl = on/' /etc/postgresql/14/main/postgresql.conf
31+
sudo apt purge postgresql-14
32+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
33+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
34+
sudo apt-get update
35+
sudo apt-get -y install "postgresql-${{ matrix.postgres }}"
36+
sudo cp ./tests/pg_hba.conf /etc/postgresql/${{ matrix.postgres }}/main/pg_hba.conf
37+
sudo sed -i 's/.*wal_level.*/wal_level = logical/' /etc/postgresql/${{ matrix.postgres }}/main/postgresql.conf
38+
sudo sed -i 's/.*ssl = .*/ssl = on/' /etc/postgresql/${{ matrix.postgres }}/main/postgresql.conf
3339
openssl req -new -x509 -nodes -days 365 -text -subj "/CN=localhost" -extensions v3_req -config <(cat /etc/ssl/openssl.cnf <(printf "\n[v3_req]\nbasicConstraints=critical,CA:TRUE\nkeyUsage=nonRepudiation,digitalSignature,keyEncipherment\nsubjectAltName=DNS:localhost")) -keyout server.key -out server.crt
34-
sudo cp server.key /etc/postgresql/14/main/server.key
35-
sudo cp server.crt /etc/postgresql/14/main/server.crt
36-
sudo chmod og-rwx /etc/postgresql/14/main/server.key
40+
sudo cp server.key /etc/postgresql/${{ matrix.postgres }}/main/server.key
41+
sudo cp server.crt /etc/postgresql/${{ matrix.postgres }}/main/server.crt
42+
sudo chmod og-rwx /etc/postgresql/${{ matrix.postgres }}/main/server.key
3743
sudo systemctl start postgresql.service
44+
sudo systemctl status postgresql.service
3845
pg_isready
46+
sudo -u postgres psql -c "SHOW hba_file;"
3947
- uses: denoland/setup-deno@v1
4048
with:
4149
deno-version: v1.x

cjs/tests/bootstrap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ exec('psql', ['-c', 'create user postgres_js_test_scram with password \'postgres
1212
exec('dropdb', ['postgres_js_test'])
1313
exec('createdb', ['postgres_js_test'])
1414
exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
15+
exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])
16+
1517

1618
module.exports.exec = exec;function exec(cmd, args) {
1719
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })

cjs/tests/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ t('Connection end does not cancel query', async() => {
557557

558558
t('Connection destroyed', async() => {
559559
const sql = postgres(options)
560-
setTimeout(() => sql.end({ timeout: 0 }), 0)
560+
process.nextTick(() => sql.end({ timeout: 0 }))
561561
return ['CONNECTION_DESTROYED', await sql``.catch(x => x.code)]
562562
})
563563

@@ -915,7 +915,7 @@ t('has server parameters', async() => {
915915
return ['postgres.js', (await sql`select 1`.then(() => sql.parameters.application_name))]
916916
})
917917

918-
t('big query body', async() => {
918+
t('big query body', { timeout: 2 }, async() => {
919919
await sql`create table test (x int)`
920920
return [50000, (await sql`insert into test ${
921921
sql([...Array(50000).keys()].map(x => ({ x })))
@@ -2125,11 +2125,11 @@ t('Cancel running query', async() => {
21252125
return ['57014', error.code]
21262126
})
21272127

2128-
t('Cancel piped query', async() => {
2128+
t('Cancel piped query', { timeout: 5 }, async() => {
21292129
await sql`select 1`
2130-
const last = sql`select pg_sleep(0.2)`.execute()
2130+
const last = sql`select pg_sleep(1)`.execute()
21312131
const query = sql`select pg_sleep(2) as dig`
2132-
setTimeout(() => query.cancel(), 100)
2132+
setTimeout(() => query.cancel(), 500)
21332133
const error = await query.catch(x => x)
21342134
await last
21352135
return ['57014', error.code]

cjs/tests/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const tests = {}
1313
const nt = module.exports.nt = () => ignored++
1414
const ot = module.exports.ot = (...rest) => (only = true, test(true, ...rest))
1515
const t = module.exports.t = (...rest) => test(false, ...rest)
16-
t.timeout = 1
16+
t.timeout = 5
1717

1818
async function test(o, name, options, fn) {
1919
typeof options !== 'object' && (fn = options, options = {})

deno/tests/bootstrap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ await exec('psql', ['-c', 'create user postgres_js_test_scram with password \'po
1212
await exec('dropdb', ['postgres_js_test'])
1313
await exec('createdb', ['postgres_js_test'])
1414
await exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
15+
await exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])
16+
1517

1618
function ignore(cmd, args) {
1719
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })

deno/tests/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ t('Connection end does not cancel query', async() => {
559559

560560
t('Connection destroyed', async() => {
561561
const sql = postgres(options)
562-
setTimeout(() => sql.end({ timeout: 0 }), 0)
562+
process.nextTick(() => sql.end({ timeout: 0 }))
563563
return ['CONNECTION_DESTROYED', await sql``.catch(x => x.code)]
564564
})
565565

@@ -917,7 +917,7 @@ t('has server parameters', async() => {
917917
return ['postgres.js', (await sql`select 1`.then(() => sql.parameters.application_name))]
918918
})
919919

920-
t('big query body', async() => {
920+
t('big query body', { timeout: 2 }, async() => {
921921
await sql`create table test (x int)`
922922
return [50000, (await sql`insert into test ${
923923
sql([...Array(50000).keys()].map(x => ({ x })))
@@ -2127,11 +2127,11 @@ t('Cancel running query', async() => {
21272127
return ['57014', error.code]
21282128
})
21292129

2130-
t('Cancel piped query', async() => {
2130+
t('Cancel piped query', { timeout: 5 }, async() => {
21312131
await sql`select 1`
2132-
const last = sql`select pg_sleep(0.2)`.execute()
2132+
const last = sql`select pg_sleep(1)`.execute()
21332133
const query = sql`select pg_sleep(2) as dig`
2134-
setTimeout(() => query.cancel(), 100)
2134+
setTimeout(() => query.cancel(), 500)
21352135
const error = await query.catch(x => x)
21362136
await last
21372137
return ['57014', error.code]

deno/tests/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const tests = {}
1414
export const nt = () => ignored++
1515
export const ot = (...rest) => (only = true, test(true, ...rest))
1616
export const t = (...rest) => test(false, ...rest)
17-
t.timeout = 1
17+
t.timeout = 5
1818

1919
async function test(o, name, options, fn) {
2020
typeof options !== 'object' && (fn = options, options = {})

tests/bootstrap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ exec('psql', ['-c', 'create user postgres_js_test_scram with password \'postgres
1212
exec('dropdb', ['postgres_js_test'])
1313
exec('createdb', ['postgres_js_test'])
1414
exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
15+
exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])
16+
1517

1618
export function exec(cmd, args) {
1719
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })

tests/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ t('Connection end does not cancel query', async() => {
557557

558558
t('Connection destroyed', async() => {
559559
const sql = postgres(options)
560-
setTimeout(() => sql.end({ timeout: 0 }), 0)
560+
process.nextTick(() => sql.end({ timeout: 0 }))
561561
return ['CONNECTION_DESTROYED', await sql``.catch(x => x.code)]
562562
})
563563

@@ -915,7 +915,7 @@ t('has server parameters', async() => {
915915
return ['postgres.js', (await sql`select 1`.then(() => sql.parameters.application_name))]
916916
})
917917

918-
t('big query body', async() => {
918+
t('big query body', { timeout: 2 }, async() => {
919919
await sql`create table test (x int)`
920920
return [50000, (await sql`insert into test ${
921921
sql([...Array(50000).keys()].map(x => ({ x })))
@@ -2125,11 +2125,11 @@ t('Cancel running query', async() => {
21252125
return ['57014', error.code]
21262126
})
21272127

2128-
t('Cancel piped query', async() => {
2128+
t('Cancel piped query', { timeout: 5 }, async() => {
21292129
await sql`select 1`
2130-
const last = sql`select pg_sleep(0.2)`.execute()
2130+
const last = sql`select pg_sleep(1)`.execute()
21312131
const query = sql`select pg_sleep(2) as dig`
2132-
setTimeout(() => query.cancel(), 100)
2132+
setTimeout(() => query.cancel(), 500)
21332133
const error = await query.catch(x => x)
21342134
await last
21352135
return ['57014', error.code]
@@ -2139,7 +2139,7 @@ t('Cancel queued query', async() => {
21392139
const query = sql`select pg_sleep(2) as nej`
21402140
const tx = sql.begin(sql => (
21412141
query.cancel(),
2142-
sql`select pg_sleep(0.1) as hej, 'hejsa'`
2142+
sql`select pg_sleep(0.5) as hej, 'hejsa'`
21432143
))
21442144
const error = await query.catch(x => x)
21452145
await tx

tests/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const tests = {}
1313
export const nt = () => ignored++
1414
export const ot = (...rest) => (only = true, test(true, ...rest))
1515
export const t = (...rest) => test(false, ...rest)
16-
t.timeout = 1
16+
t.timeout = 5
1717

1818
async function test(o, name, options, fn) {
1919
typeof options !== 'object' && (fn = options, options = {})

0 commit comments

Comments
 (0)