Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create failing test for https://github.com/sidorares/node-mysql2/issues/1847 #1899

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
4 changes: 3 additions & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down