Skip to content

Commit fe9d669

Browse files
author
Dorian Sechesan
committed
Create failing test for sidorares#1847
1 parent 57ccce7 commit fe9d669

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

test/common.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ exports.waitDatabaseReady = function(callback) {
5353
tryConnect();
5454
};
5555

56-
exports.createConnection = function(args) {
57-
58-
const driver = require('../index.js');
56+
function createConnectionFromDriver(driver, args) {
5957
if (!args?.port && process.env.MYSQL_CONNECTION_URL) {
6058
return driver.createConnection({ ...args, uri: process.env.MYSQL_CONNECTION_URL })
6159
}
@@ -88,6 +86,18 @@ exports.createConnection = function(args) {
8886

8987
const conn = driver.createConnection(params);
9088
return conn;
89+
}
90+
91+
exports.createConnection = function(args) {
92+
93+
const driver = require('../index.js');
94+
return createConnectionFromDriver(driver, args);
95+
};
96+
97+
exports.createConnectionPromise = function(args) {
98+
99+
const driver = require('../promise.js');
100+
return createConnectionFromDriver(driver, args);
91101
};
92102

93103
exports.getConfig = function(input) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as common from '../../common.js';
2+
import assert from 'node:assert';
3+
4+
function killConnection(connectionId) {
5+
const killer = common.createConnection();
6+
killer.query('KILL ?', [connectionId]);
7+
killer.end();
8+
}
9+
10+
const connection = await common.createConnectionPromise();
11+
const query = connection.connection.query('SELECT SLEEP(10)');
12+
const stream = query.stream();
13+
14+
// kill the connection
15+
killConnection(connection.threadId);
16+
17+
try {
18+
// iterate the streaming result here
19+
for await (const row of stream) {
20+
// do stuff with row
21+
}
22+
assert.fail('The query stream should have thrown the connection error');
23+
} catch (e) {
24+
assert.ok('The query stream has thrown the connection error');
25+
}

test/run.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const options = {
77
};
88

99
if (process.env.FILTER) {
10-
options.include = new RegExp(`${process.env.FILTER}.*\\.js$`);
10+
options.include = new RegExp(`${process.env.FILTER}.*\\.m?js$`);
1111
}
1212

1313
require('urun')(__dirname, options);

0 commit comments

Comments
 (0)