Skip to content

Commit

Permalink
Test more PostgreSQL and Node versions in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed May 31, 2023
1 parent 5862a7d commit db26c62
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 28 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ on: [push, pull_request]

jobs:
test:
name: Test Node v${{ matrix.node }}
name: Node v${{ matrix.node }} on PostgreSQL v${{ matrix.postgres }}
strategy:
fail-fast: false
matrix:
node: ['12', '14', '16', '17', '18']
node: ['12', '14', '16', '18', '20']
postgres: ['12', '13', '14', '15']
runs-on: ubuntu-latest
services:
postgres:
image: postgres
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
Expand All @@ -27,15 +28,22 @@ jobs:
- uses: actions/checkout@v3
- run: |
date
sudo cp ./tests/pg_hba.conf /etc/postgresql/14/main/pg_hba.conf
sudo sed -i 's/.*wal_level.*/wal_level = logical/' /etc/postgresql/14/main/postgresql.conf
sudo sed -i 's/.*ssl = .*/ssl = on/' /etc/postgresql/14/main/postgresql.conf
sudo apt purge postgresql-14
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install "postgresql-${{ matrix.postgres }}"
sudo cp ./tests/pg_hba.conf /etc/postgresql/${{ matrix.postgres }}/main/pg_hba.conf
sudo sed -i 's/.*wal_level.*/wal_level = logical/' /etc/postgresql/${{ matrix.postgres }}/main/postgresql.conf
sudo sed -i 's/.*ssl = .*/ssl = on/' /etc/postgresql/${{ matrix.postgres }}/main/postgresql.conf
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
sudo cp server.key /etc/postgresql/14/main/server.key
sudo cp server.crt /etc/postgresql/14/main/server.crt
sudo chmod og-rwx /etc/postgresql/14/main/server.key
sudo cp server.key /etc/postgresql/${{ matrix.postgres }}/main/server.key
sudo cp server.crt /etc/postgresql/${{ matrix.postgres }}/main/server.crt
sudo chmod og-rwx /etc/postgresql/${{ matrix.postgres }}/main/server.key
sudo systemctl start postgresql.service
sudo systemctl status postgresql.service
pg_isready
sudo -u postgres psql -c "SHOW hba_file;"
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
Expand Down
2 changes: 2 additions & 0 deletions cjs/tests/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exec('psql', ['-c', 'create user postgres_js_test_scram with password \'postgres
exec('dropdb', ['postgres_js_test'])
exec('createdb', ['postgres_js_test'])
exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])


module.exports.exec = exec;function exec(cmd, args) {
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })
Expand Down
10 changes: 5 additions & 5 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ t('Connection end does not cancel query', async() => {

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

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

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

t('Cancel piped query', async() => {
t('Cancel piped query', { timeout: 5 }, async() => {
await sql`select 1`
const last = sql`select pg_sleep(0.2)`.execute()
const last = sql`select pg_sleep(1)`.execute()
const query = sql`select pg_sleep(2) as dig`
setTimeout(() => query.cancel(), 100)
setTimeout(() => query.cancel(), 500)
const error = await query.catch(x => x)
await last
return ['57014', error.code]
Expand Down
2 changes: 1 addition & 1 deletion cjs/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const tests = {}
const nt = module.exports.nt = () => ignored++
const ot = module.exports.ot = (...rest) => (only = true, test(true, ...rest))
const t = module.exports.t = (...rest) => test(false, ...rest)
t.timeout = 1
t.timeout = 5

async function test(o, name, options, fn) {
typeof options !== 'object' && (fn = options, options = {})
Expand Down
2 changes: 2 additions & 0 deletions deno/tests/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ await exec('psql', ['-c', 'create user postgres_js_test_scram with password \'po
await exec('dropdb', ['postgres_js_test'])
await exec('createdb', ['postgres_js_test'])
await exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
await exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])


function ignore(cmd, args) {
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })
Expand Down
10 changes: 5 additions & 5 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ t('Connection end does not cancel query', async() => {

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

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

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

t('Cancel piped query', async() => {
t('Cancel piped query', { timeout: 5 }, async() => {
await sql`select 1`
const last = sql`select pg_sleep(0.2)`.execute()
const last = sql`select pg_sleep(1)`.execute()
const query = sql`select pg_sleep(2) as dig`
setTimeout(() => query.cancel(), 100)
setTimeout(() => query.cancel(), 500)
const error = await query.catch(x => x)
await last
return ['57014', error.code]
Expand Down
2 changes: 1 addition & 1 deletion deno/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const tests = {}
export const nt = () => ignored++
export const ot = (...rest) => (only = true, test(true, ...rest))
export const t = (...rest) => test(false, ...rest)
t.timeout = 1
t.timeout = 5

async function test(o, name, options, fn) {
typeof options !== 'object' && (fn = options, options = {})
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exec('psql', ['-c', 'create user postgres_js_test_scram with password \'postgres
exec('dropdb', ['postgres_js_test'])
exec('createdb', ['postgres_js_test'])
exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])


export function exec(cmd, args) {
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })
Expand Down
12 changes: 6 additions & 6 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ t('Connection end does not cancel query', async() => {

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

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

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

t('Cancel piped query', async() => {
t('Cancel piped query', { timeout: 5 }, async() => {
await sql`select 1`
const last = sql`select pg_sleep(0.2)`.execute()
const last = sql`select pg_sleep(1)`.execute()
const query = sql`select pg_sleep(2) as dig`
setTimeout(() => query.cancel(), 100)
setTimeout(() => query.cancel(), 500)
const error = await query.catch(x => x)
await last
return ['57014', error.code]
Expand All @@ -2139,7 +2139,7 @@ t('Cancel queued query', async() => {
const query = sql`select pg_sleep(2) as nej`
const tx = sql.begin(sql => (
query.cancel(),
sql`select pg_sleep(0.1) as hej, 'hejsa'`
sql`select pg_sleep(0.5) as hej, 'hejsa'`
))
const error = await query.catch(x => x)
await tx
Expand Down
2 changes: 1 addition & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const tests = {}
export const nt = () => ignored++
export const ot = (...rest) => (only = true, test(true, ...rest))
export const t = (...rest) => test(false, ...rest)
t.timeout = 1
t.timeout = 5

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

0 comments on commit db26c62

Please sign in to comment.