Skip to content
Permalink
Browse files
[misc] adding test coverage (compression multi-packet + buffer skippi…
…ng numeric)
  • Loading branch information
rusher committed Aug 25, 2018
1 parent 0221c53 commit ea105f8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
@@ -251,7 +251,7 @@ Bench.prototype.endConnection = function(conn) {
console.log(err);
}
if (conn.pool) {
if (conn.pool.on) conn.pool.on('error', err => {});
if (conn.pool.on) conn.pool.on("error", err => {});
conn.pool.end().catch(err => {
console.log("ending error for pool '" + conn.desc + "'");
console.log(err);
@@ -5,7 +5,7 @@ const { assert } = require("chai");

describe("Compression", function() {
const testSize = 16 * 1024 * 1024 + 800; // more than one packet
let maxAllowedSize, buf;
let maxAllowedSize, buf, randomBuf;
let conn;

before(function(done) {
@@ -17,8 +17,10 @@ describe("Compression", function() {
maxAllowedSize = row[0].t;
if (testSize < maxAllowedSize) {
buf = Buffer.alloc(testSize);
randomBuf = Buffer.alloc(testSize);
for (let i = 0; i < buf.length; i++) {
buf[i] = 97 + (i % 10);
randomBuf[i] = Math.floor(Math.random() * 255);
}
}
done();
@@ -76,4 +78,20 @@ describe("Compression", function() {
})
.catch(done);
});

it("multi compression packet size", function(done) {
if (maxAllowedSize <= testSize) this.skip();
this.timeout(10000); //can take some time
conn.query("CREATE TEMPORARY TABLE bigParameter2 (b longblob)");
conn
.query("insert into bigParameter2(b) values(?)", [randomBuf])
.then(() => {
return conn.query("SELECT * from bigParameter2");
})
.then(rows => {
assert.deepEqual(rows[0].b, randomBuf);
done();
})
.catch(done);
});
});
@@ -0,0 +1,51 @@
"use strict";

const Utils = require("../../../lib/misc/utils");
const { assert } = require("chai");
const Packet = require("../../../lib/io/packet");

describe("packet", () => {
const head = Buffer.from([0xaa, 0xbb, 0xcc, 0x33]);
const buf = Buffer.from([0xf0, 0x9f, 0xa4, 0x98, 0xf0, 0x9f, 0x92, 0xaa]); // 🤘💪
const longbuf = Buffer.from([
0x00,
0x01,
0x02,
0x03,
0x04,
0x05,
0x06,
0x07,
0x08,
0x09,
0x0a,
0x0b,
0x0c,
0x0d,
0x0e,
0x0f,
0x10
]);

it("skipping integer", () => {
let packet = new Packet(Buffer.allocUnsafe(1000), 0, 1000);
packet.buf[0] = 0;
packet.buf[1] = 10;
packet.buf[12] = 251;
packet.buf[13] = 252;
packet.buf[14] = 1;
packet.buf[15] = 1;
packet.buf[273] = 253;
packet.buf[274] = 1;
packet.buf[275] = 1;
packet.buf[276] = 0;
packet.skipLengthCodedNumber();
packet.skipLengthCodedNumber();
packet.skipLengthCodedNumber();
packet.skipLengthCodedNumber();
packet.skipLengthCodedNumber();

assert.equal(packet.pos, 534);
});

});

0 comments on commit ea105f8

Please sign in to comment.