diff --git a/test/common.js b/test/common.js index 6ba5ff332e..432ee997d8 100644 --- a/test/common.js +++ b/test/common.js @@ -53,9 +53,7 @@ exports.waitDatabaseReady = function(callback) { tryConnect(); }; -exports.createConnection = function(args) { - - const driver = require('../index.js'); +function createConnectionFromDriver(driver, args) { if (!args?.port && process.env.MYSQL_CONNECTION_URL) { return driver.createConnection({ ...args, uri: process.env.MYSQL_CONNECTION_URL }) } @@ -88,6 +86,18 @@ exports.createConnection = function(args) { const conn = driver.createConnection(params); return conn; +} + +exports.createConnection = function(args) { + + const driver = require('../index.js'); + return createConnectionFromDriver(driver, args); +}; + +exports.createConnectionPromise = function(args) { + + const driver = require('../promise.js'); + return createConnectionFromDriver(driver, args); }; exports.getConfig = function(input) { diff --git a/test/integration/connection/test-query-stream-errors-propagation.mjs b/test/integration/connection/test-query-stream-errors-propagation.mjs new file mode 100644 index 0000000000..3ea6a4b0d7 --- /dev/null +++ b/test/integration/connection/test-query-stream-errors-propagation.mjs @@ -0,0 +1,25 @@ +import * as common from '../../common.js'; +import assert from 'node:assert'; + +function killConnection(connectionId) { + const killer = common.createConnection(); + killer.query('KILL ?', [connectionId]); + killer.end(); +} + +const connection = await common.createConnectionPromise(); +const query = connection.connection.query('SELECT SLEEP(10)'); +const stream = query.stream(); + +// kill the connection +killConnection(connection.threadId); + +try { + // iterate the streaming result here + for await (const row of stream) { + // do stuff with row + } + assert.fail('The query stream should have thrown the connection error'); +} catch (e) { + assert.ok('The query stream has thrown the connection error'); +} diff --git a/test/run.js b/test/run.js index 3f32c8ca91..910900ff81 100755 --- a/test/run.js +++ b/test/run.js @@ -7,7 +7,9 @@ const options = { }; if (process.env.FILTER) { - options.include = new RegExp(`${process.env.FILTER}.*\\.js$`); + options.include = new RegExp(`${process.env.FILTER}.*\\.m?js$`); +} else { + options.include = /test-.+\.m?js$/ } require('urun')(__dirname, options);