Skip to content

Commit

Permalink
Merge pull request #1813 from sidorares/planetscale-ci
Browse files Browse the repository at this point in the history
ci: add PlanetScale to CI
  • Loading branch information
sidorares committed Jan 31, 2023
2 parents 7956989 + b91ef1f commit 24126ab
Show file tree
Hide file tree
Showing 40 changed files with 230 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": ["prettier", "eslint:recommended", "plugin:markdown/recommended"],
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2022
},
"plugins": ["markdown", "async-await"],
"env": {
Expand Down
25 changes: 17 additions & 8 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
mysql-version: ["mysql:8.0.18", "mysql:8.0.22", "mysql:5.7"]
use-compression: [0]
use-tls: [0]
mysql_connection_url_key: [""]
# TODO - add mariadb to the matrix. currently few tests are broken due to mariadb incompatibilities
include:
- node-version: "16.x"
Expand All @@ -51,26 +52,32 @@ jobs:
mysql-version: "mysql:5.7"
use-compression: 0
use-tls: 0
- node-version: "12.x"
mysql-version: "mysql:5.7"
use-compression: 0
use-tls: 0
- filter: "test-select-1"
- filter: "test-select-1" # a number of tests does not work with mysql 5.1 due to old sql syntax, just testing basic connection
node-version: "16.x"
mysql-version: "datagrip/mysql:5.1"
use-compression: 0
use-tls: 0
- node-version: "18.x"
mysql_connection_url_key: "PS_MYSQL_URL"
use-compression: 0
use-tls: 0
env:
MYSQL_CONNECTION_URL: ${{ secrets[matrix.mysql_connection_url_key] }}

name: Node.js ${{ matrix.node-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}}
name: Node.js ${{ matrix.node-version }} - DB ${{ matrix.mysql-version }}${{ matrix.mysql_connection_url_key }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}}

steps:
- uses: actions/checkout@v3

- name: Set up MySQL
run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_ROOT_PASSWORD=${{ env.MYSQL_PASSWORD }} -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/examples/custom-conf:/etc/mysql/conf.d -v $PWD/examples/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }}
if: ${{ !startsWith(env.MYSQL_CONNECTION_URL, 'mysql://') }}
run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/examples/custom-conf:/etc/mysql/conf.d -v $PWD/examples/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }}

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Cache dependencies
uses: actions/cache@v3
with:
Expand All @@ -80,14 +87,16 @@ jobs:

- name: Install npm dependencies
run: npm ci

- name: Wait mysql server is ready
if: ${{ !startsWith(env.MYSQL_CONNECTION_URL, 'mysql://') }}
run: node tools/wait-up.js

- name: Run tests
run: FILTER=${{matrix.filter}} MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} npm run coverage-test

- run: echo "coverage-artifact-name=`echo -n "${{github.run_id}}-${{ matrix.node-version }}-${{ matrix.mysql-version }}-${{matrix.use-tls}}-${{matrix.use-compression}}" | shasum | cut -d " " -f 1`" >> $GITHUB_ENV
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: coverage-${{env.coverage-artifact-name}}
path: coverage/cobertura-coverage.xml
Expand Down
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"eslint-plugin-async-await": "0.0.0",
"eslint-plugin-markdown": "^3.0.0",
"husky": "^8.0.2",
"is-async-supported": "^1.2.0",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"portfinder": "^1.0.28",
Expand Down
21 changes: 15 additions & 6 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ exports.waitDatabaseReady = function(callback) {
};

exports.createConnection = function(args) {

const driver = require('../index.js');
if (!args?.port && process.env.MYSQL_CONNECTION_URL) {
return driver.createConnection({ ...args, uri: process.env.MYSQL_CONNECTION_URL })
}

if (!args) {
args = {};
}
Expand All @@ -80,8 +86,6 @@ exports.createConnection = function(args) {
connectTimeout: args && args.connectTimeout,
};

// previously we had an adapter logic to benchmark against mysqljs/mysql and libmariaclient
const driver = require('../index.js');
const conn = driver.createConnection(params);
return conn;
};
Expand Down Expand Up @@ -114,10 +118,15 @@ exports.getConfig = function(input) {
};

exports.createPool = function(args) {
let driver = require('../index.js');
if (!args?.port && process.env.MYSQL_CONNECTION_URL) {
return driver.createPool({ ...args, uri: process.env.MYSQL_CONNECTION_URL })
}

if (!args) {
args = {};
}
let driver = require('../index.js');

if (process.env.BENCHMARK_MYSQL1) {
driver = require('mysql');
}
Expand All @@ -126,9 +135,9 @@ exports.createPool = function(args) {
};

exports.createPoolCluster = function(args = {}) {
let driver = require('../index.js');
if (process.env.BENCHMARK_MYSQL1) {
driver = require('mysql');
const driver = require('../index.js');
if (!args?.port && process.env.MYSQL_CONNECTION_URL) {
return driver.createPoolCluster({ ...args, uri: process.env.MYSQL_CONNECTION_URL })
}
return driver.createPoolCluster(args)
}
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/encoding/test-charset-results.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale (unsupported non utf8 charsets)');
process.exit(0);
}

const mysql = require('../../../../index.js');
const common = require('../../../common');
const connection = common.createConnection();
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/encoding/test-client-encodings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale (unsupported non utf8 charsets)');
process.exit(0);
}

const common = require('../../../common');
const assert = require('assert');

Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/encoding/test-non-bmp-chars.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const common = require('../../../common');
const assert = require('assert');

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

// 4 bytes in utf8
const pileOfPoo = '💩';

Expand Down
8 changes: 4 additions & 4 deletions test/integration/connection/encoding/test-track-encodings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const text = 'привет, мир';

connection.query('SET character_set_client=koi8r', err => {
assert.ifError(err);
connection.query('SELECT ?', [text], (err, rows) => {
connection.query(`SELECT ? as result`, [text], (err, rows) => {
assert.ifError(err);
assert.equal(rows[0][text], text);
assert.equal(rows[0].result, text);
connection.query('SET character_set_client=cp1251', err => {
assert.ifError(err);
connection.query('SELECT ?', [text], (err, rows) => {
connection.query(`SELECT ? as result`, [text], (err, rows) => {
assert.ifError(err);
assert.equal(rows[0][text], text);
assert.equal(rows[0].result, text);
connection.end();
});
});
Expand Down
6 changes: 6 additions & 0 deletions test/integration/connection/test-binary-charset-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const common = require('../../common');
const connection = common.createConnection();
const assert = require('assert');

// TODO - this could be re-enabled
if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

let rows = undefined;
let fields = undefined;
let rows1 = undefined;
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/test-binary-multiple-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const mysql = require('../../common.js').createConnection({
multipleStatements: true
});
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/test-change-user-plugin-auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const assert = require('assert');
const common = require('../../common');
const connection = common.createConnection();
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/test-change-user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const assert = require('assert');
const common = require('../../common');
const connection = common.createConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ portfinder.getPort((err, port) => {
const server = mysql.createServer();
server.listen(port);
server.on('connection', conn => {
console.log('Here!');
conn.close();
});

Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/test-connect-with-uri.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

if (process.env.MYSQL_CONNECTION_URL) {
console.log('skipping test when mysql server is configured using MYSQL_CONNECTION_URL');
process.exit(0);
}

const common = require('../../common');
const connection = common.createConnectionWithURI();
const assert = require('assert');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const connection = common.createConnection();

// Test that we ignore a ECONNRESET error if the connection
// is already closing, we close and then emit the error
connection.query(`select 1`, (err, rows) => {
connection.query(`select 1 as "1"`, (err, rows) => {
assert.equal(rows[0]['1'], 1);
connection.close();
connection.stream.emit('error', error);
Expand Down
6 changes: 6 additions & 0 deletions test/integration/connection/test-errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

// different error codes for PS, disabling for now
if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const common = require('../../common');
const connection = common.createConnection();
const assert = require('assert');
Expand Down
2 changes: 1 addition & 1 deletion test/integration/connection/test-execute-cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ connection.execute(q, [123], (err, _rows) => {
throw err;
}
rows2 = _rows;
assert(connection._statements.length === 1);
assert(connection._statements.size === 1);
assert(connection._statements.get(key).query === q);
assert(connection._statements.get(key).parameters.length === 1);
connection.end();
Expand Down
6 changes: 6 additions & 0 deletions test/integration/connection/test-execute-nocolumndef.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

'use strict';

// different error codes for PS, disabling for now
if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const common = require('../../common');
const connection = common.createConnection();
const assert = require('assert-diff');
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/test-load-infile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const common = require('../../common');
const connection = common.createConnection();
const assert = require('assert');
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection/test-multiple-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

'use strict';

if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) {
console.log('skipping test for planetscale');
process.exit(0);
}

const mysql = require('../../common.js').createConnection({
multipleStatements: true
});
Expand Down
9 changes: 4 additions & 5 deletions test/integration/connection/test-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ const connection = common.createConnection();
const assert = require('assert');

let rows, rows1;
let fields, fields1;
let fields1;

connection.query('CREATE TEMPORARY TABLE t (i int)');
connection.query('INSERT INTO t VALUES(null)');
connection.query('SELECT cast(NULL AS CHAR)', (err, _rows, _fields) => {
connection.query('SELECT cast(NULL AS CHAR) as cast_result', (err, _rows) => {
if (err) {
throw err;
}
rows = _rows;
fields = _fields;
});
connection.query('SELECT * from t', (err, _rows, _fields) => {
if (err) {
Expand All @@ -26,8 +25,8 @@ connection.query('SELECT * from t', (err, _rows, _fields) => {
});

process.on('exit', () => {
assert.deepEqual(rows, [{ 'cast(NULL AS CHAR)': null }]);
assert.equal(fields[0].columnType, 253);
assert.deepEqual(rows, [{ 'cast_result': null }]);
// assert.equal(fields[0].columnType, 253); // depeding on the server type could be 253 or 3, disabling this check for now
assert.deepEqual(rows1, [{ i: null }]);
assert.equal(fields1[0].columnType, 3);
});
7 changes: 3 additions & 4 deletions test/integration/connection/test-select-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const assert = require('assert');
const common = require('../../common');
const connection = common.createConnection();

connection.query('SELECT 1', (err, rows, fields) => {
console.log('query callback', err, rows, fields);
connection.query('SELECT 1 as result', (err, rows, fields) => {
assert.ifError(err);
assert.deepEqual(rows, [{ 1: 1 }]);
assert.equal(fields[0].name, '1');
assert.deepEqual(rows, [{ result: 1 }]);
assert.equal(fields[0].name, 'result');
connection.end();
});
Loading

0 comments on commit 24126ab

Please sign in to comment.