@@ -11,8 +11,8 @@ common.getTestConnection(function (err, connection) {
11
11
12
12
var oldMaxAllowedPacket ;
13
13
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 ) ;
16
16
17
17
oldMaxAllowedPacket = Number ( rows [ 0 ] . Value ) ;
18
18
@@ -29,9 +29,8 @@ function increaseMaxAllowedPacketIfNeeded(connection) {
29
29
? minMaxAllowedPacket
30
30
: oldMaxAllowedPacket ;
31
31
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 ) ;
35
34
36
35
// We need to re-connect for this change to take effect, bah
37
36
connection . end ( ) ;
@@ -40,35 +39,44 @@ function increaseMaxAllowedPacketIfNeeded(connection) {
40
39
// We need to wait for the re-connect to happen before starting the actual
41
40
// test. That's because our buffer to hex shim in 0.4.x takes ~12 sec on
42
41
// 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 ) ;
45
44
46
45
triggerLargeQueryAndResponsePackets ( connection ) ;
47
46
} ) ;
48
47
} ) ;
49
48
}
50
49
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' ;
53
53
54
54
function triggerLargeQueryAndResponsePackets ( connection ) {
55
- var random = crypto . pseudoRandomBytes || crypto . randomBytes ; // Depends on node.js version
56
- var sql = 'SELECT ? as bigField, ? as trailingField' ;
57
-
58
55
random ( length , function ( err , buf ) {
59
56
assert . ifError ( err ) ;
60
57
assert . equal ( buf . length , length ) ;
61
58
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 ) {
63
72
assert . ifError ( err ) ;
64
73
65
74
connection . query ( 'SET GLOBAL max_allowed_packet = ?' , [ oldMaxAllowedPacket ] , assert . ifError ) ;
66
75
connection . end ( function ( err ) {
67
76
assert . ifError ( err ) ;
68
77
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' ) ) ;
72
80
} ) ;
73
81
} ) ;
74
82
} ) ;
0 commit comments