Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit a6841f9

Browse files
authored
multiple backends testing improved (#723)
* build once test many * one container per test
1 parent 44899df commit a6841f9

3 files changed

Lines changed: 82 additions & 50 deletions

File tree

.github/workflows/test.yml

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,38 @@ name: test
33
on: [push, pull_request]
44

55
jobs:
6-
test:
6+
build:
77
runs-on: ubuntu-20.04
88

9-
services:
10-
# postgres:
11-
# image: postgres:10.8
12-
# env:
13-
# POSTGRES_USER: postgres
14-
# POSTGRES_PASSWORD: postgres
15-
# POSTGRES_DB: pgbd
16-
# ports:
17-
# - 5432:5432
18-
# # needed because the postgres container does not provide a healthcheck
19-
# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
9+
strategy:
10+
matrix:
11+
node-version: [12.x]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
21+
- name: Build for ${{ matrix.node-version }}
22+
run: scripts/build.sh
2023

21-
mariadb:
22-
image: mariadb:10.3
23-
ports:
24-
- 13306:3306
25-
env:
26-
MYSQL_USER: user
27-
MYSQL_PASSWORD: password
28-
MYSQL_DATABASE: db
29-
MYSQL_ROOT_PASSWORD: password
30-
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=5
24+
- name: Store artifacts
25+
uses: actions/upload-artifact@v1
26+
with:
27+
name: built_node${{ matrix.node-version }}
28+
path: server/public
3129

32-
mssql:
33-
image: mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
34-
env:
35-
ACCEPT_EULA: Y
36-
SA_PASSWORD: SuperP4ssw0rd!
37-
MSSQL_PID: Developer
38-
ports:
39-
- 1433:1433
30+
test:
31+
needs: build
32+
runs-on: ubuntu-20.04
4033

4134
strategy:
4235
fail-fast: false # if one job fails, others will not be aborted
4336
matrix:
44-
db_uri: [
45-
'mssql://sa:SuperP4ssw0rd!@localhost:1433/dbname',
46-
# 'postgres://postgres:postgres@localhost:5432/pgdb',
47-
'mysql://root:root@localhost:3306/db2',
48-
'mariadb://root:password@localhost:13306/db',
49-
''
50-
]
37+
backendtype: [ '', 'mssql','mysql', 'mariadb', 'postgres' ]
5138
node-version: [12.x]
5239

5340
steps:
@@ -58,13 +45,21 @@ jobs:
5845
with:
5946
node-version: ${{ matrix.node-version }}
6047

61-
- name: Build
62-
run: scripts/build.sh
48+
- name: Install node modules
49+
run: npm ci --prefix server
50+
51+
- name: Download built artifacts
52+
uses: actions/download-artifact@v1
53+
with:
54+
name: built_node${{ matrix.node-version }}
55+
path: server/public
6356

64-
- name: Enable mysql server included in ubuntu-20.04 image
65-
run: sudo systemctl start mysql.service
57+
- name: Enable backend server
58+
if: ${{ matrix.backendtype }}
59+
run: |
60+
docker-compose -f server/docker-compose.yml up -d ${{ matrix.backendtype }}
61+
# Wait until container becomes healthy
62+
docker-compose -f server/docker-compose.yml events | grep --max-count 1 'health_status: healthy'
6663
6764
- name: Test
68-
env:
69-
SQLPAD_BACKEND_DB_URI: ${{ matrix.db_uri }}
70-
run: npm run test --prefix server
65+
run: npm run test${{ matrix.backendtype }} --prefix server

server/docker-compose.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ services:
99
- ACCEPT_EULA=Y
1010
- MSSQL_SA_PASSWORD=SuperP4ssw0rd!
1111
- MSSQL_PID=Express
12+
healthcheck:
13+
test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", "SuperP4ssw0rd!", "-Q", "SELECT 1" ]
14+
interval: 3s
15+
timeout: 3s
16+
retries: 10
17+
1218
postgres:
1319
image: postgres:9.6-alpine
1420
environment:
@@ -17,12 +23,39 @@ services:
1723
POSTGRES_DB: sqlpad
1824
ports:
1925
- '5432:5432'
20-
mysql:
26+
healthcheck:
27+
test: ["CMD", "pg_isready"]
28+
interval: 5s
29+
timeout: 2s
30+
retries: 10
31+
32+
mariadb:
2133
image: mariadb:10.3
34+
ports:
35+
- 13306:3306
2236
environment:
23-
MYSQL_ROOT_PASSWORD: sqlpad
24-
MYSQL_DATABASE: sqlpad
25-
MYSQL_USER: sqlpad
26-
MYSQL_PASSWORD: sqlpad
37+
MYSQL_USER: user
38+
MYSQL_PASSWORD: password
39+
MYSQL_DATABASE: db
40+
MYSQL_ROOT_PASSWORD: password
41+
healthcheck:
42+
test: ["CMD", "mysqladmin", "ping"]
43+
interval: 5s
44+
timeout: 2s
45+
retries: 10
46+
47+
mysql:
48+
image: mysql:8
2749
ports:
28-
- '3306:3306'
50+
- 3306:3306
51+
environment:
52+
MYSQL_USER: user
53+
MYSQL_PASSWORD: password
54+
MYSQL_DATABASE: db2
55+
MYSQL_ROOT_PASSWORD: root
56+
healthcheck:
57+
test: ["CMD", "mysqladmin", "ping"]
58+
interval: 5s
59+
timeout: 2s
60+
retries: 10
61+

server/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"prepublishOnly": "cd .. && ./scripts/build.sh",
3333
"start": "node-dev server.js --config \"./config.dev.ini\" | pino-pretty",
3434
"test": "mocha test --timeout 10000 --recursive --exit --bail",
35+
"testmssql" : "env SQLPAD_BACKEND_DB_URI='mssql://sa:SuperP4ssw0rd!@localhost:1433/dbname' npm run test",
36+
"testmysql" : "env SQLPAD_BACKEND_DB_URI='mysql://root:root@localhost:3306/db2' npm run test",
37+
"testmariadb" : "env SQLPAD_BACKEND_DB_URI='mariadb://root:password@localhost:13306/db' npm run test",
38+
"testpostgres" : "env SQLPAD_BACKEND_DB_URI='postgres://sqlpad:sqlpad@localhost:5432/sqlpad' npm run test",
3539
"fixlint": "eslint --fix \"**/*.js\"",
3640
"lint": "eslint \"**/*.js\""
3741
},

0 commit comments

Comments
 (0)