Skip to content

Commit 7ec5d09

Browse files
committed
Merge branch 'master' into develop
2 parents 8f88f9d + 0b8da71 commit 7ec5d09

File tree

2 files changed

+95
-114
lines changed

2 files changed

+95
-114
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* CONJS-277 using connection.importFile when connection is not connected to database result in error
1414
* CONJS-278 Possible buffer overwrite when sending query bigger than 16M
1515
* CONJS-282 error when using mysql_clear_test password authentication plugin
16+
* CONJS-283 wrong decoding of binary unsigned MEDIUMINT
1617

1718

1819
## [3.2.3](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/3.2.3) (Dec 2023)

test/integration/test-debug.js

Lines changed: 94 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ describe('debug', () => {
1717
const smallFileName = path.join(os.tmpdir(), 'smallLocalInfileDebug.txt');
1818

1919
let permitLocalInfile = true;
20-
let tmpLogFile = path.join(os.tmpdir(), 'combined.txt');
2120
let logger;
2221
let setNameAddition = 0;
22+
let fileIncrement = 0;
2323

2424
before(async function () {
2525
if (!isXpand()) {
2626
try {
27-
fs.unlinkSync(tmpLogFile);
27+
fs.unlinkSync(path.join(os.tmpdir(), 'combined*.txt'));
2828
} catch (e) {}
2929
const rows = await shareConn.query('select @@local_infile');
3030
permitLocalInfile = rows[0]['@@local_infile'] === 1 || rows[0]['@@local_infile'] === 1n;
@@ -38,6 +38,7 @@ describe('debug', () => {
3838
});
3939

4040
beforeEach(async function () {
41+
let tmpLogFile = path.join(os.tmpdir(), 'combined' + ++fileIncrement + '.txt');
4142
logger = winston.createLogger({
4243
transports: [new winston.transports.File({ filename: tmpLogFile })]
4344
});
@@ -46,6 +47,7 @@ describe('debug', () => {
4647

4748
//ensure that debug from previous test are written to console
4849
afterEach(async function () {
50+
let tmpLogFile = path.join(os.tmpdir(), 'combined' + fileIncrement + '.txt');
4951
await closeLogger(logger);
5052
try {
5153
fs.unlinkSync(tmpLogFile);
@@ -59,120 +61,98 @@ describe('debug', () => {
5961
}
6062
});
6163

62-
it('select request debug', function (done) {
63-
testQueryDebug(false, done);
64+
it('select request debug', async function () {
65+
await testQueryDebug(false);
6466
});
6567

66-
it('select request debug compress', function (done) {
68+
it('select request debug compress', async function () {
6769
if (isXpand()) this.skip();
68-
testQueryDebug(true, done);
70+
await testQueryDebug(true);
6971
});
7072

71-
function testQueryDebug(compress, done) {
72-
base
73-
.createConnection({
74-
compress: compress,
75-
prepareCacheLength: 0,
76-
logger: {
77-
network: null,
78-
query: (msg) => logger.info(msg),
79-
error: (msg) => logger.info(msg)
80-
}
81-
})
82-
.then((conn) => {
83-
conn
84-
.query('CREATE TABLE debugVoid (val int)')
85-
.then(() => {
86-
if (compress && !isMaxscale() && process.env.srv !== 'skysql' && process.env.srv !== 'skysql-ha') {
87-
conn.debugCompress((msg) => logger.info(msg));
88-
} else {
89-
conn.debug((msg) => logger.info(msg));
90-
}
91-
return conn.query('SELECT 2');
92-
})
93-
.then(() => {
94-
if (compress && !isMaxscale() && process.env.srv !== 'skysql' && process.env.srv !== 'skysql-ha') {
95-
conn.debugCompress(false);
96-
} else {
97-
conn.debug(false);
98-
}
99-
return conn.query('SELECT 3');
100-
})
101-
.then(() => {
102-
return conn.prepare('SELECT ?');
103-
})
104-
.then((prepare) => {
105-
return prepare.execute(['t']).then((res) => prepare.close());
106-
})
107-
.then(() => {
108-
return conn.batch('INSERT INTO debugVoid VALUES (?)', [[1], [2]]);
109-
})
110-
.then(() => {
111-
return conn.end();
112-
})
113-
.then(() => {
114-
//wait 100ms to ensure stream has been written
115-
setTimeout(() => {
116-
const serverVersion = conn.serverVersion();
117-
if (isMaxscale() || process.env.srv === 'skysql' || process.env.srv === 'skysql-ha') compress = false;
118-
const rangeWithEOF = compress ? [1500, 2000] : [1800, 4250];
119-
const rangeWithoutEOF = compress ? [1500, 2000] : [2350, 3250];
120-
const data = fs.readFileSync(tmpLogFile, 'utf8');
121-
console.log(data);
122-
assert.isTrue(data.includes('QUERY: SELECT 3'));
123-
assert.isTrue(data.includes('PREPARE:'));
124-
assert.isTrue(data.includes('EXECUTE:'));
125-
assert.isTrue(data.includes("SELECT ? - parameters:['t']"));
126-
assert.isTrue(data.includes('CLOSE PREPARE:'));
127-
if (conn.info.isMariaDB() && conn.info.hasMinVersion(10, 2, 2)) {
128-
assert.isTrue(data.includes('BULK:'));
129-
assert.isTrue(data.includes('INSERT INTO debugVoid VALUES (?) - parameters:[[1],[2]]'));
130-
}
131-
assert.isTrue(data.includes('QUIT'));
132-
if (
133-
((conn.info.isMariaDB() && conn.info.hasMinVersion(10, 2, 2)) ||
134-
(!conn.info.isMariaDB() && conn.info.hasMinVersion(5, 7, 5))) &&
135-
!isMaxscale() &&
136-
process.env.srv !== 'skysql' &&
137-
process.env.srv !== 'skysql-ha'
138-
) {
139-
assert(
140-
data.length > rangeWithoutEOF[0] && data.length < rangeWithoutEOF[1],
141-
'wrong data length : ' +
142-
data.length +
143-
' expected value between ' +
144-
rangeWithoutEOF[0] +
145-
' and ' +
146-
rangeWithoutEOF[1] +
147-
'.' +
148-
'\n server version : ' +
149-
serverVersion +
150-
'\n data :\n' +
151-
data
152-
);
153-
} else {
154-
//EOF Packet make exchange bigger
155-
assert(
156-
data.length > rangeWithEOF[0] && data.length < rangeWithEOF[1],
157-
'wrong data length : ' +
158-
data.length +
159-
' expected value between ' +
160-
rangeWithEOF[0] +
161-
' and ' +
162-
rangeWithEOF[1] +
163-
'.' +
164-
'\n server version : ' +
165-
serverVersion +
166-
'\n data :\n' +
167-
data
168-
);
169-
}
170-
done();
171-
}, 100);
172-
})
173-
.catch(done);
174-
})
175-
.catch(done);
73+
async function testQueryDebug(compress) {
74+
const conn = await base.createConnection({
75+
compress: compress,
76+
prepareCacheLength: 0,
77+
logger: {
78+
network: null,
79+
query: (msg) => logger.info(msg),
80+
error: (msg) => logger.info(msg)
81+
}
82+
});
83+
await conn.query('CREATE TABLE debugVoid (val int)');
84+
if (compress && !isMaxscale() && process.env.srv !== 'skysql' && process.env.srv !== 'skysql-ha') {
85+
conn.debugCompress((msg) => logger.info(msg));
86+
} else {
87+
conn.debug((msg) => logger.info(msg));
88+
}
89+
await conn.query('SELECT 2');
90+
if (compress && !isMaxscale() && process.env.srv !== 'skysql' && process.env.srv !== 'skysql-ha') {
91+
conn.debugCompress(false);
92+
} else {
93+
conn.debug(false);
94+
}
95+
await conn.query('SELECT 3');
96+
const prepare = await conn.prepare('SELECT ?');
97+
await prepare.execute(['t']).then((res) => prepare.close());
98+
await conn.batch('INSERT INTO debugVoid VALUES (?)', [[1], [2]]);
99+
conn.end();
100+
//wait 100ms to ensure stream has been written
101+
await new Promise((resolve) => new setTimeout(resolve, 100));
102+
const serverVersion = conn.serverVersion();
103+
if (isMaxscale() || process.env.srv === 'skysql' || process.env.srv === 'skysql-ha') compress = false;
104+
const rangeWithEOF = compress ? [1500, 2000] : [1800, 4250];
105+
const rangeWithoutEOF = compress ? [1500, 2000] : [2350, 3250];
106+
const data = fs.readFileSync(path.join(os.tmpdir(), 'combined' + fileIncrement + '.txt'), 'utf8');
107+
console.log(data);
108+
assert.isTrue(data.includes('QUERY: SELECT 3'));
109+
assert.isTrue(data.includes('PREPARE:'));
110+
assert.isTrue(data.includes('EXECUTE:'));
111+
assert.isTrue(data.includes("SELECT ? - parameters:['t']"));
112+
assert.isTrue(data.includes('CLOSE PREPARE:'));
113+
if (conn.info.isMariaDB() && conn.info.hasMinVersion(10, 2, 2)) {
114+
assert.isTrue(data.includes('BULK:'));
115+
assert.isTrue(data.includes('INSERT INTO debugVoid VALUES (?) - parameters:[[1],[2]]'));
116+
}
117+
assert.isTrue(data.includes('QUIT'));
118+
if (
119+
((conn.info.isMariaDB() && conn.info.hasMinVersion(10, 2, 2)) ||
120+
(!conn.info.isMariaDB() && conn.info.hasMinVersion(5, 7, 5))) &&
121+
!isMaxscale() &&
122+
process.env.srv !== 'skysql' &&
123+
process.env.srv !== 'skysql-ha'
124+
) {
125+
assert(
126+
data.length > rangeWithoutEOF[0] && data.length < rangeWithoutEOF[1],
127+
'wrong data length : ' +
128+
data.length +
129+
' expected value between ' +
130+
rangeWithoutEOF[0] +
131+
' and ' +
132+
rangeWithoutEOF[1] +
133+
'.' +
134+
'\n server version : ' +
135+
serverVersion +
136+
'\n data :\n' +
137+
data
138+
);
139+
} else {
140+
//EOF Packet make exchange bigger
141+
assert(
142+
data.length > rangeWithEOF[0] && data.length < rangeWithEOF[1],
143+
'wrong data length : ' +
144+
data.length +
145+
' expected value between ' +
146+
rangeWithEOF[0] +
147+
' and ' +
148+
rangeWithEOF[1] +
149+
'.' +
150+
'\n server version : ' +
151+
serverVersion +
152+
'\n data :\n' +
153+
data
154+
);
155+
}
176156
}
177157

178158
it('select big request (compressed data) debug', function (done) {
@@ -191,7 +171,7 @@ describe('debug', () => {
191171
.end()
192172
.then(() => {
193173
const serverVersion = conn.serverVersion();
194-
const data = fs.readFileSync(tmpLogFile, 'utf8');
174+
const data = fs.readFileSync(path.join(os.tmpdir(), 'combined' + fileIncrement + '.txt'), 'utf8');
195175
let range = [8900, 12000 + setNameAddition];
196176
assert(
197177
data.length > range[0] && data.length < range[1],
@@ -283,7 +263,7 @@ describe('debug', () => {
283263
conn.end();
284264
//wait 100ms to ensure stream has been written
285265
setTimeout(() => {
286-
const data = fs.readFileSync(tmpLogFile, 'utf8');
266+
const data = fs.readFileSync(path.join(os.tmpdir(), 'combined' + fileIncrement + '.txt'), 'utf8');
287267
const serverVersion = conn.serverVersion();
288268
const range = [7500, 11000 + (Conf.baseConfig.ssl ? 800 : 0) + setNameAddition];
289269
assert(
@@ -337,7 +317,7 @@ describe('debug', () => {
337317
const serverVersion = conn.serverVersion();
338318
if (isMaxscale() || process.env.srv === 'skysql' || process.env.srv === 'skysql-ha') compress = false;
339319
const range = compress ? [60, 180] : [60, 170];
340-
const data = fs.readFileSync(tmpLogFile, 'utf8');
320+
const data = fs.readFileSync(path.join(os.tmpdir(), 'combined' + fileIncrement + '.txt'), 'utf8');
341321
assert.isTrue(data.includes('PING'));
342322
assert.isTrue(data.includes('QUIT'));
343323

0 commit comments

Comments
 (0)