Skip to content

Commit 8ea9f69

Browse files
committed
test: store the value in large packet test
1 parent f099536 commit 8ea9f69

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

test/integration/connection/test-send-and-receive-large-packets.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ common.getTestConnection(function (err, connection) {
1111

1212
var oldMaxAllowedPacket;
1313
function getMaxAllowedPacket(connection) {
14-
connection.query('SHOW VARIABLES WHERE Variable_name = ?', ['max_allowed_packet'], function(err, rows) {
15-
if (err) throw err;
14+
connection.query('SHOW VARIABLES WHERE Variable_name = ?', ['max_allowed_packet'], function (err, rows) {
15+
assert.ifError(err);
1616

1717
oldMaxAllowedPacket = Number(rows[0].Value);
1818

@@ -29,9 +29,8 @@ function increaseMaxAllowedPacketIfNeeded(connection) {
2929
? minMaxAllowedPacket
3030
: oldMaxAllowedPacket;
3131

32-
connection.query('SET GLOBAL max_allowed_packet = ?', [newMaxAllowedPacket], function(err, rows) {
33-
if (err) throw err;
34-
32+
connection.query('SET GLOBAL max_allowed_packet = ?', [newMaxAllowedPacket], function (err, rows) {
33+
assert.ifError(err);
3534

3635
// We need to re-connect for this change to take effect, bah
3736
connection.end();
@@ -40,35 +39,44 @@ function increaseMaxAllowedPacketIfNeeded(connection) {
4039
// We need to wait for the re-connect to happen before starting the actual
4140
// test. That's because our buffer to hex shim in 0.4.x takes ~12 sec on
4241
// TravisCI, causing a MySQL connection timeout otherwise.
43-
connection.connect(function(err) {
44-
if (err) throw err;
42+
connection.connect(function (err) {
43+
assert.ifError(err);
4544

4645
triggerLargeQueryAndResponsePackets(connection);
4746
});
4847
});
4948
}
5049

51-
var length = (Math.pow(256, 3) / 2) + 10; // Half, because of hex encoding
52-
var trailing = 'tailing text';
50+
var length = (Math.pow(256, 3) / 2) + 10; // Half, because of hex encoding
51+
var random = crypto.pseudoRandomBytes || crypto.randomBytes; // Depends on node.js version
52+
var table = 'large_packet_test';
5353

5454
function triggerLargeQueryAndResponsePackets(connection) {
55-
var random = crypto.pseudoRandomBytes || crypto.randomBytes; // Depends on node.js version
56-
var sql = 'SELECT ? as bigField, ? as trailingField';
57-
5855
random(length, function (err, buf) {
5956
assert.ifError(err);
6057
assert.equal(buf.length, length);
6158

62-
connection.query(sql, [buf, trailing], function (err, rows) {
59+
common.useTestDb(connection);
60+
61+
connection.query([
62+
'CREATE TEMPORARY TABLE ?? (',
63+
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
64+
'`bb` longblob NOT NULL,',
65+
'PRIMARY KEY (`id`)',
66+
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
67+
].join('\n'), [table], assert.ifError);
68+
69+
connection.query('INSERT INTO ?? SET ?', [table, {bb: buf}], assert.ifError);
70+
71+
connection.query('SELECT `id`, `bb` FROM ??', [table], function (err, rows) {
6372
assert.ifError(err);
6473

6574
connection.query('SET GLOBAL max_allowed_packet = ?', [oldMaxAllowedPacket], assert.ifError);
6675
connection.end(function (err) {
6776
assert.ifError(err);
6877
assert.equal(rows.length, 1);
69-
assert.equal(rows[0].trailingField, trailing);
70-
assert.equal(rows[0].bigField.length, buf.length);
71-
assert.equal(rows[0].bigField.toString('base64'), buf.toString('base64'));
78+
assert.equal(rows[0].bb.length, buf.length);
79+
assert.equal(rows[0].bb.toString('base64'), buf.toString('base64'));
7280
});
7381
});
7482
});

0 commit comments

Comments
 (0)