From b91ef1f4d5174aefa44d33d1d0dbcf640046b7f5 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Mon, 30 Jan 2023 08:15:08 +0000 Subject: [PATCH] ci: add PlanetScale to CI --- .eslintrc | 2 +- .github/workflows/ci-linux.yml | 25 ++++--- package-lock.json | 7 -- package.json | 1 - test/common.js | 21 ++++-- .../encoding/test-charset-results.js | 5 ++ .../encoding/test-client-encodings.js | 5 ++ .../connection/encoding/test-non-bmp-chars.js | 5 ++ .../encoding/test-track-encodings.js | 8 +-- .../connection/test-binary-charset-string.js | 6 ++ .../test-binary-multiple-results.js | 5 ++ .../test-change-user-plugin-auth.js | 5 ++ .../connection/test-change-user.js | 5 ++ .../test-connect-connection-closed-error.js | 1 - .../connection/test-connect-with-uri.js | 5 ++ .../test-connection-reset-while-closing.js | 2 +- test/integration/connection/test-errors.js | 6 ++ .../connection/test-execute-cached.js | 2 +- .../connection/test-execute-nocolumndef.js | 6 ++ .../connection/test-load-infile.js | 5 ++ .../connection/test-multiple-results.js | 5 ++ test/integration/connection/test-null.js | 9 ++- test/integration/connection/test-select-1.js | 7 +- .../connection/test-select-empty-string.js | 7 +- .../connection/test-select-utf8.js | 7 +- .../connection/test-track-state-change.js | 5 ++ .../connection/test-update-changed-rows.js | 8 +++ .../promise-wrappers/test-async-stack.js | 70 +++++-------------- .../promise-wrappers/test-promise-wrappers.js | 5 ++ test/integration/regressions/test-#433.js | 6 ++ test/integration/regressions/test-#485.js | 11 ++- test/integration/regressions/test-#617.js | 9 +++ test/integration/test-pool-disconnect.js | 9 ++- test/integration/test-pool-release.js | 19 ++--- test/integration/test-server-close.js | 6 ++ .../test-connection-error-remove.js | 6 ++ .../pool-cluster/test-connection-order.js | 6 ++ .../pool-cluster/test-connection-restore.js | 6 ++ test/unit/pool-cluster/test-connection-rr.js | 6 ++ test/unit/pool-cluster/test-query.js | 6 ++ 40 files changed, 230 insertions(+), 110 deletions(-) diff --git a/.eslintrc b/.eslintrc index 02896d7546..aae4877b1c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "extends": ["prettier", "eslint:recommended", "plugin:markdown/recommended"], "parserOptions": { - "ecmaVersion": 2017 + "ecmaVersion": 2022 }, "plugins": ["markdown", "async-await"], "env": { diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 57c511ab4c..d6dc17c917 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -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" @@ -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: @@ -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 diff --git a/package-lock.json b/package-lock.json index adee977abd..1b0edd170f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,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", @@ -1799,12 +1798,6 @@ "url": "/~https://github.com/sponsors/wooorm" } }, - "node_modules/is-async-supported": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/is-async-supported/-/is-async-supported-1.2.0.tgz", - "integrity": "sha512-q/aXUFAWM99eq6epMQM0DmNnecSX621A80Ua9dwnVW9XlxfzSK34I9D9uMBIJ5aNFJjRCcNeLUCTOcpvC80g7A==", - "dev": true - }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", diff --git a/package.json b/package.json index 92db05af70..e32368228f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/common.js b/test/common.js index d06f327957..6ba5ff332e 100644 --- a/test/common.js +++ b/test/common.js @@ -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 = {}; } @@ -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; }; @@ -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'); } @@ -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) } diff --git a/test/integration/connection/encoding/test-charset-results.js b/test/integration/connection/encoding/test-charset-results.js index 2c1d75ff62..c62091969f 100644 --- a/test/integration/connection/encoding/test-charset-results.js +++ b/test/integration/connection/encoding/test-charset-results.js @@ -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(); diff --git a/test/integration/connection/encoding/test-client-encodings.js b/test/integration/connection/encoding/test-client-encodings.js index b4df96fc56..de382d6084 100644 --- a/test/integration/connection/encoding/test-client-encodings.js +++ b/test/integration/connection/encoding/test-client-encodings.js @@ -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'); diff --git a/test/integration/connection/encoding/test-non-bmp-chars.js b/test/integration/connection/encoding/test-non-bmp-chars.js index 7dcf0abbe4..457280eae0 100644 --- a/test/integration/connection/encoding/test-non-bmp-chars.js +++ b/test/integration/connection/encoding/test-non-bmp-chars.js @@ -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 = '💩'; diff --git a/test/integration/connection/encoding/test-track-encodings.js b/test/integration/connection/encoding/test-track-encodings.js index 88135b3944..f48638dd6c 100644 --- a/test/integration/connection/encoding/test-track-encodings.js +++ b/test/integration/connection/encoding/test-track-encodings.js @@ -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(); }); }); diff --git a/test/integration/connection/test-binary-charset-string.js b/test/integration/connection/test-binary-charset-string.js index 57d546cf40..b641660656 100644 --- a/test/integration/connection/test-binary-charset-string.js +++ b/test/integration/connection/test-binary-charset-string.js @@ -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; diff --git a/test/integration/connection/test-binary-multiple-results.js b/test/integration/connection/test-binary-multiple-results.js index de02974f6f..e3c8f4ed6a 100644 --- a/test/integration/connection/test-binary-multiple-results.js +++ b/test/integration/connection/test-binary-multiple-results.js @@ -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 }); diff --git a/test/integration/connection/test-change-user-plugin-auth.js b/test/integration/connection/test-change-user-plugin-auth.js index 059d2d2668..d23c590b8f 100644 --- a/test/integration/connection/test-change-user-plugin-auth.js +++ b/test/integration/connection/test-change-user-plugin-auth.js @@ -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(); diff --git a/test/integration/connection/test-change-user.js b/test/integration/connection/test-change-user.js index 059d2d2668..d23c590b8f 100644 --- a/test/integration/connection/test-change-user.js +++ b/test/integration/connection/test-change-user.js @@ -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(); diff --git a/test/integration/connection/test-connect-connection-closed-error.js b/test/integration/connection/test-connect-connection-closed-error.js index f6efc3bd6a..84e7749db2 100644 --- a/test/integration/connection/test-connect-connection-closed-error.js +++ b/test/integration/connection/test-connect-connection-closed-error.js @@ -11,7 +11,6 @@ portfinder.getPort((err, port) => { const server = mysql.createServer(); server.listen(port); server.on('connection', conn => { - console.log('Here!'); conn.close(); }); diff --git a/test/integration/connection/test-connect-with-uri.js b/test/integration/connection/test-connect-with-uri.js index 1af14948e9..358089b7df 100644 --- a/test/integration/connection/test-connect-with-uri.js +++ b/test/integration/connection/test-connect-with-uri.js @@ -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'); diff --git a/test/integration/connection/test-connection-reset-while-closing.js b/test/integration/connection/test-connection-reset-while-closing.js index 30426d51e4..4a831e90a1 100644 --- a/test/integration/connection/test-connection-reset-while-closing.js +++ b/test/integration/connection/test-connection-reset-while-closing.js @@ -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); diff --git a/test/integration/connection/test-errors.js b/test/integration/connection/test-errors.js index 213109f518..35f6649a2a 100644 --- a/test/integration/connection/test-errors.js +++ b/test/integration/connection/test-errors.js @@ -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'); diff --git a/test/integration/connection/test-execute-cached.js b/test/integration/connection/test-execute-cached.js index 1cb688bd4f..472ed687ae 100644 --- a/test/integration/connection/test-execute-cached.js +++ b/test/integration/connection/test-execute-cached.js @@ -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(); diff --git a/test/integration/connection/test-execute-nocolumndef.js b/test/integration/connection/test-execute-nocolumndef.js index 42d0f17d58..596856da95 100644 --- a/test/integration/connection/test-execute-nocolumndef.js +++ b/test/integration/connection/test-execute-nocolumndef.js @@ -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'); diff --git a/test/integration/connection/test-load-infile.js b/test/integration/connection/test-load-infile.js index e219f96ee0..7091a2a5a4 100644 --- a/test/integration/connection/test-load-infile.js +++ b/test/integration/connection/test-load-infile.js @@ -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'); diff --git a/test/integration/connection/test-multiple-results.js b/test/integration/connection/test-multiple-results.js index e9be7febe4..449a33ded2 100644 --- a/test/integration/connection/test-multiple-results.js +++ b/test/integration/connection/test-multiple-results.js @@ -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 }); diff --git a/test/integration/connection/test-null.js b/test/integration/connection/test-null.js index 0317866115..62c73dcd00 100644 --- a/test/integration/connection/test-null.js +++ b/test/integration/connection/test-null.js @@ -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) { @@ -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); }); diff --git a/test/integration/connection/test-select-1.js b/test/integration/connection/test-select-1.js index b7066bda6c..e9f9dfa2e7 100644 --- a/test/integration/connection/test-select-1.js +++ b/test/integration/connection/test-select-1.js @@ -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(); }); \ No newline at end of file diff --git a/test/integration/connection/test-select-empty-string.js b/test/integration/connection/test-select-empty-string.js index dfff0166a8..1672eb980d 100644 --- a/test/integration/connection/test-select-empty-string.js +++ b/test/integration/connection/test-select-empty-string.js @@ -4,16 +4,17 @@ const common = require('../../common'); const connection = common.createConnection(); const assert = require('assert'); -let rows; -connection.query('SELECT ""', (err, _rows) => { +let rows, fields; +connection.query('SELECT ""', (err, _rows, _fields) => { if (err) { throw err; } rows = _rows; + fields = _fields; connection.end(); }); process.on('exit', () => { - assert.deepEqual(rows, [{ '': '' }]); + assert.deepEqual(rows, [{ [fields[0].name]: '' }]); }); diff --git a/test/integration/connection/test-select-utf8.js b/test/integration/connection/test-select-utf8.js index d1b0d87889..7a7e9f8e77 100644 --- a/test/integration/connection/test-select-utf8.js +++ b/test/integration/connection/test-select-utf8.js @@ -5,18 +5,15 @@ const connection = common.createConnection(); const assert = require('assert'); let rows = undefined; -let fields = undefined; const multibyteText = '本日は晴天なり'; -connection.query(`SELECT '${multibyteText}'`, (err, _rows, _fields) => { +connection.query(`SELECT '${multibyteText}' as result`, (err, _rows) => { if (err) { throw err; } rows = _rows; - fields = _fields; connection.end(); }); process.on('exit', () => { - assert.equal(rows[0][multibyteText], multibyteText); - assert.equal(fields[0].name, multibyteText); + assert.equal(rows[0].result, multibyteText); }); diff --git a/test/integration/connection/test-track-state-change.js b/test/integration/connection/test-track-state-change.js index 616e16f6a4..f30d59d066 100644 --- a/test/integration/connection/test-track-state-change.js +++ b/test/integration/connection/test-track-state-change.js @@ -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'); diff --git a/test/integration/connection/test-update-changed-rows.js b/test/integration/connection/test-update-changed-rows.js index 0cf2354690..4ea38b287f 100644 --- a/test/integration/connection/test-update-changed-rows.js +++ b/test/integration/connection/test-update-changed-rows.js @@ -1,5 +1,13 @@ 'use strict'; +// "changedRows" is not part of the mysql protocol and extracted from "info string" response +// while valid for most mysql servers, it's not guaranteed to be present in all cases +if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { + console.log('skipping test for planetscale'); + process.exit(0); +} + + /** * created at 2016.09.17 15:24:34 * diff --git a/test/integration/promise-wrappers/test-async-stack.js b/test/integration/promise-wrappers/test-async-stack.js index ea39eb45fe..7398406f0b 100644 --- a/test/integration/promise-wrappers/test-async-stack.js +++ b/test/integration/promise-wrappers/test-async-stack.js @@ -1,24 +1,18 @@ 'use strict'; -const code = ` -'use strict'; - const config = require('../../common.js').config; const assert = require('assert'); -const isAsyncSupported = require('is-async-supported'); const ErrorStackParser = require('error-stack-parser'); -let skipTest = false; -if (!isAsyncSupported) { - console.log('no async/await support, skipping test'); - skipTest = true; - process.exit(0); -} - -const createConnection = require('../../../promise.js').createConnection; -const createPool = require('../../../promise.js').createPool; +const createConnection = async function(args) { + const connect = require('../../../promise.js').createConnection; + if (!args && process.env.MYSQL_CONNECTION_URL) { + return connect({ uri: process.env.MYSQL_CONNECTION_URL }); + } + return connect({ ...config, ...args }); +}; -function test() { +async function test() { // TODO check this is actially required. This meant as a help for pre async/await node // to load entire file and do isAsyncSupported check instead of failing with syntax error @@ -27,22 +21,12 @@ function test() { // TODO: investigate why connection is still open after ENETUNREACH async function test1() { e1 = new Error(); - const conn = await createConnection({ host: '0.42.42.42' }); - let [rows, fields] = conn.query('select 1 + 1'); - await Promise.all([conn.query('select 1+1'), conn.query('syntax error')]); + // expected not to connect + await createConnection({ host: '127.0.0.1', port: 33066 }); } - /* - test1().catch(err => { - const stack = ErrorStackParser.parse(err); - const stackExpected = ErrorStackParser.parse(e1); - assert(stack[1].getLineNumber() === stackExpected[0].getLineNumber() + 1); - }); - */ - async function test2() { - const conn = await createConnection(config); - let [rows, fields] = await conn.query('select 1 + 1'); + const conn = await createConnection(); try { e2 = new Error(); await Promise.all([conn.query('select 1+1'), conn.query('syntax error')]); @@ -54,30 +38,12 @@ function test() { } } - test2(); + test1().catch(err => { + const stack = ErrorStackParser.parse(err); + const stackExpected = ErrorStackParser.parse(e1); + assert(stack[2].getLineNumber() === stackExpected[0].getLineNumber() + 2); + test2(); + }); } -test(); -`; - -process.on('unhandledRejection', err => { - console.log(err.stack); -}); - -const vm = require('vm'); - -try { - vm.runInNewContext( - code, - { - require: require - }, - { - fileName: __filename, - lineOffset: 1 - } - ); -} catch (err) { - // ignore sync errors (must be syntax - async/await not supported) - console.log(err); -} +test(); \ No newline at end of file diff --git a/test/integration/promise-wrappers/test-promise-wrappers.js b/test/integration/promise-wrappers/test-promise-wrappers.js index 1bc64bdc7d..08fc554d5d 100644 --- a/test/integration/promise-wrappers/test-promise-wrappers.js +++ b/test/integration/promise-wrappers/test-promise-wrappers.js @@ -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 config = require('../../common.js').config; const assert = require('assert'); diff --git a/test/integration/regressions/test-#433.js b/test/integration/regressions/test-#433.js index 7deedd04fd..2abd97f7a9 100644 --- a/test/integration/regressions/test-#433.js +++ b/test/integration/regressions/test-#433.js @@ -1,5 +1,11 @@ 'use strict'; +// TODO: reach out to PlanetScale to clarify charset support +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({ charset: 'KOI8R_GENERAL_CI' }); const assert = require('assert'); diff --git a/test/integration/regressions/test-#485.js b/test/integration/regressions/test-#485.js index b2aa1e58e8..41e3866901 100644 --- a/test/integration/regressions/test-#485.js +++ b/test/integration/regressions/test-#485.js @@ -3,9 +3,16 @@ const config = require('../../common.js').config; const assert = require('assert'); -const createPool = require('../../../promise.js').createPool; +const createPoolPromise = require('../../../promise.js').createPool; const PoolConnection = require('../../../lib/pool_connection.js'); +function createPool(args) { + if (!args && process.env.MYSQL_CONNECTION_URL) { + return createPoolPromise({ uri: process.env.MYSQL_CONNECTION_URL }); + } + return createPoolPromise({ ...config, ...args }); +} + // stub const release = PoolConnection.prototype.release; let releaseCalls = 0; @@ -14,7 +21,7 @@ PoolConnection.prototype.release = function() { }; function testPoolPromiseExecuteLeak() { - const pool = createPool(config); + const pool = createPool(); pool .execute('select 1+2 as ttt') .then(result => { diff --git a/test/integration/regressions/test-#617.js b/test/integration/regressions/test-#617.js index a8438fbf73..7338c00254 100644 --- a/test/integration/regressions/test-#617.js +++ b/test/integration/regressions/test-#617.js @@ -1,5 +1,13 @@ 'use strict'; +// PlanetScale response has trailing 000 in 2017-07-26 09:36:42.000 +// TODO: rewrite test to account for variations. Skipping for now on PS +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({ dateStrings: true }); const assert = require('assert'); @@ -56,6 +64,7 @@ connection.query( ); process.on('exit', () => { + console.log(actualRows); expected.map((exp, index) => { const row = actualRows[index]; Object.keys(exp).map(key => { diff --git a/test/integration/test-pool-disconnect.js b/test/integration/test-pool-disconnect.js index 435180079b..bab226e4c5 100644 --- a/test/integration/test-pool-disconnect.js +++ b/test/integration/test-pool-disconnect.js @@ -3,6 +3,13 @@ const assert = require('assert'); const mysql = require('../common'); +// planetscale does not support KILL, skipping this test +// https://planetscale.com/docs/reference/mysql-compatibility +if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { + console.log('skipping test, planetscale does not support KILL'); + process.exit(0); +} + const pool = mysql.createPool(); const conn = mysql.createConnection({ multipleStatements: true }); pool.config.connectionLimit = 5; @@ -18,7 +25,7 @@ function kill() { if (typeof id !== 'undefined') { // sleep required to give mysql time to close connection, // and callback called after connection with id is really closed - conn.query('kill ?; select sleep(0.05)', id, err => { + conn.query('kill ?; select sleep(0.05)', [id], err => { assert.ifError(err); killCount++; // TODO: this assertion needs to be fixed, after kill diff --git a/test/integration/test-pool-release.js b/test/integration/test-pool-release.js index d74c6f4af9..292cf79d6f 100644 --- a/test/integration/test-pool-release.js +++ b/test/integration/test-pool-release.js @@ -3,24 +3,27 @@ const createPool = require('../common.js').createPool; const assert = require('assert'); -const pool = createPool(); +const pool = createPool({ + idleTimeout: 15000 +}); pool.query('test sql', () => { pool.query('test sql', [], () => { pool.query('test sql', [], () => { pool.query('test sql', [], () => { - pool.query('test sql', () => { - pool.query('test sql').on('error', () => { + pool.query('test sql', () => { + pool.query('test sql').on('error', () => { pool.query('test sql', () => { - pool.execute('test sql', () => { - pool.execute('test sql', () => { - pool.execute('test sql', [], () => { - pool.execute('test sql', () => { + pool.execute('test sql', () => { + pool.execute('test sql', () => { + pool.execute('test sql', [], () => { + pool.execute('test sql', () => { pool.execute('test sql', () => { // TODO change order events are fires so that connection is released before callback // that way this number will be more deterministic assert(pool._allConnections.length < 3); - assert(pool._freeConnections.length === 1); + // on some setups with small CLIENT_INTERACTION_TIMEOUT value connection might be closed by the time we get here, hence "one or zero" + assert(pool._freeConnections.length <= 1); assert(pool._connectionQueue.length === 0); pool.end(); }); diff --git a/test/integration/test-server-close.js b/test/integration/test-server-close.js index 5c893a9621..23df672de2 100644 --- a/test/integration/test-server-close.js +++ b/test/integration/test-server-close.js @@ -7,6 +7,12 @@ const common = require('../common'); const connection = common.createConnection(); const assert = require('assert'); +if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { + console.log('skipping test for planetscale'); + process.exit(0); +} + + const customWaitTimeout = 1; // seconds let error; diff --git a/test/unit/pool-cluster/test-connection-error-remove.js b/test/unit/pool-cluster/test-connection-error-remove.js index 796b33312a..e87f478952 100644 --- a/test/unit/pool-cluster/test-connection-error-remove.js +++ b/test/unit/pool-cluster/test-connection-error-remove.js @@ -1,5 +1,11 @@ 'use strict'; +// TODO: config poolCluster to work with MYSQL_CONNECTION_URL run +if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { + console.log('skipping test for planetscale'); + process.exit(0); +} + const assert = require('assert'); const portfinder = require('portfinder'); diff --git a/test/unit/pool-cluster/test-connection-order.js b/test/unit/pool-cluster/test-connection-order.js index 5e177c82d1..06946b4647 100644 --- a/test/unit/pool-cluster/test-connection-order.js +++ b/test/unit/pool-cluster/test-connection-order.js @@ -1,5 +1,11 @@ 'use strict'; +// TODO: config poolCluster to work with MYSQL_CONNECTION_URL run +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 cluster = common.createPoolCluster(); diff --git a/test/unit/pool-cluster/test-connection-restore.js b/test/unit/pool-cluster/test-connection-restore.js index 11f7ab918d..dde1f9ae9c 100644 --- a/test/unit/pool-cluster/test-connection-restore.js +++ b/test/unit/pool-cluster/test-connection-restore.js @@ -1,5 +1,11 @@ 'use strict'; +// TODO: config poolCluster to work with MYSQL_CONNECTION_URL run +if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { + console.log('skipping test for planetscale'); + process.exit(0); +} + if (process.platform === 'win32') { console.log('This test is known to fail on windows. FIXME: investi=gate why'); process.exit(0); diff --git a/test/unit/pool-cluster/test-connection-rr.js b/test/unit/pool-cluster/test-connection-rr.js index 1d94146cb6..95bcbb32f7 100644 --- a/test/unit/pool-cluster/test-connection-rr.js +++ b/test/unit/pool-cluster/test-connection-rr.js @@ -1,5 +1,11 @@ 'use strict'; +// TODO: config poolCluster to work with MYSQL_CONNECTION_URL run +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 cluster = common.createPoolCluster(); diff --git a/test/unit/pool-cluster/test-query.js b/test/unit/pool-cluster/test-query.js index e2ee1e0894..6502a1e6e5 100644 --- a/test/unit/pool-cluster/test-query.js +++ b/test/unit/pool-cluster/test-query.js @@ -1,5 +1,11 @@ 'use strict'; +// TODO: config poolCluster to work with MYSQL_CONNECTION_URL run +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 cluster = common.createPoolCluster();