From db26c62931beab186bbef2ad5c16586f6c429da2 Mon Sep 17 00:00:00 2001 From: Rasmus Porsager Date: Wed, 31 May 2023 19:49:34 +0200 Subject: [PATCH] Test more PostgreSQL and Node versions in CI --- .github/workflows/test.yml | 26 +++++++++++++++++--------- cjs/tests/bootstrap.js | 2 ++ cjs/tests/index.js | 10 +++++----- cjs/tests/test.js | 2 +- deno/tests/bootstrap.js | 2 ++ deno/tests/index.js | 10 +++++----- deno/tests/test.js | 2 +- tests/bootstrap.js | 2 ++ tests/index.js | 12 ++++++------ tests/test.js | 2 +- 10 files changed, 42 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4e3b9bb..3af94064 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 diff --git a/cjs/tests/bootstrap.js b/cjs/tests/bootstrap.js index 15295975..524d5aba 100644 --- a/cjs/tests/bootstrap.js +++ b/cjs/tests/bootstrap.js @@ -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' }) diff --git a/cjs/tests/index.js b/cjs/tests/index.js index 40a7b763..f93c6e14 100644 --- a/cjs/tests/index.js +++ b/cjs/tests/index.js @@ -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)] }) @@ -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 }))) @@ -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] diff --git a/cjs/tests/test.js b/cjs/tests/test.js index 348d18bc..c2f2721a 100644 --- a/cjs/tests/test.js +++ b/cjs/tests/test.js @@ -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 = {}) diff --git a/deno/tests/bootstrap.js b/deno/tests/bootstrap.js index da602d7c..f6eeddf5 100644 --- a/deno/tests/bootstrap.js +++ b/deno/tests/bootstrap.js @@ -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' }) diff --git a/deno/tests/index.js b/deno/tests/index.js index 351898e2..0276d4c6 100644 --- a/deno/tests/index.js +++ b/deno/tests/index.js @@ -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)] }) @@ -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 }))) @@ -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] diff --git a/deno/tests/test.js b/deno/tests/test.js index 8d063055..f61a253f 100644 --- a/deno/tests/test.js +++ b/deno/tests/test.js @@ -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 = {}) diff --git a/tests/bootstrap.js b/tests/bootstrap.js index 6a4fa4c1..b30ca14b 100644 --- a/tests/bootstrap.js +++ b/tests/bootstrap.js @@ -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' }) diff --git a/tests/index.js b/tests/index.js index 3bc7e0e8..18111887 100644 --- a/tests/index.js +++ b/tests/index.js @@ -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)] }) @@ -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 }))) @@ -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] @@ -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 diff --git a/tests/test.js b/tests/test.js index 383cd29e..5cd58b66 100644 --- a/tests/test.js +++ b/tests/test.js @@ -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 = {})