File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
test/integration/connection Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ Connection.prototype.connect = function(cb) {
31
31
32
32
this . _socket . on ( 'error' , this . _handleNetworkError . bind ( this ) ) ;
33
33
this . _protocol . on ( 'unhandledError' , this . _handleProtocolError . bind ( this ) ) ;
34
+ this . _protocol . on ( 'drain' , this . _handleProtocolDrain . bind ( this ) ) ;
34
35
this . _protocol . on ( 'end' , this . _handleProtocolEnd . bind ( this ) ) ;
35
36
}
36
37
@@ -128,6 +129,10 @@ Connection.prototype._handleProtocolError = function(err) {
128
129
this . emit ( 'error' , err ) ;
129
130
} ;
130
131
132
+ Connection . prototype . _handleProtocolDrain = function ( err ) {
133
+ this . emit ( 'drain' , err ) ;
134
+ } ;
135
+
131
136
Connection . prototype . _handleProtocolEnd = function ( err ) {
132
137
this . emit ( 'end' , err ) ;
133
138
} ;
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ Protocol.prototype._dequeue = function() {
195
195
196
196
var sequence = this . _queue [ 0 ] ;
197
197
if ( ! sequence ) {
198
+ this . emit ( 'drain' ) ;
198
199
return ;
199
200
}
200
201
Original file line number Diff line number Diff line change
1
+ var common = require ( '../../common' ) ;
2
+ var connection = common . createConnection ( ) ;
3
+ var assert = require ( 'assert' ) ;
4
+
5
+ connection . connect ( ) ;
6
+
7
+ var got_drain = false ;
8
+
9
+ connection . on ( 'drain' , function ( ) {
10
+ got_drain = true ;
11
+ } ) ;
12
+
13
+ connection . query ( "SELECT 1" , function ( err ) {
14
+ assert . equal ( got_drain , false ) ;
15
+ assert . ok ( ! err ) ;
16
+ process . nextTick ( function ( ) {
17
+ assert . equal ( got_drain , true ) ;
18
+ connection . end ( ) ;
19
+ } ) ;
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments