@@ -89,6 +89,7 @@ describe('connection tests', function () {
89
89
assert ( called ) ;
90
90
done ( ) ;
91
91
} ) ;
92
+ // TODO: In v.3 the quit command would be fired right away, so bool should be true
92
93
assert . strictEqual ( bool , false ) ;
93
94
} ) ;
94
95
@@ -99,6 +100,18 @@ describe('connection tests', function () {
99
100
assert . strictEqual ( bool , false ) ;
100
101
} ) ;
101
102
103
+ it ( 'quit "succeeds" even if the client connection is closed while doing so' , function ( done ) {
104
+ client = redis . createClient ( ) ;
105
+ client . set ( 'foo' , 'bar' , function ( err , res ) {
106
+ assert . strictEqual ( res , 'OK' ) ;
107
+ client . quit ( function ( err , res ) {
108
+ assert . strictEqual ( res , 'OK' ) ;
109
+ done ( err ) ;
110
+ } ) ;
111
+ client . end ( true ) ; // Flushing the quit command should result in a success
112
+ } ) ;
113
+ } ) ;
114
+
102
115
it ( 'quit right away if connection drops while quit command is on the fly' , function ( done ) {
103
116
client = redis . createClient ( ) ;
104
117
client . once ( 'ready' , function ( ) {
@@ -119,7 +132,7 @@ describe('connection tests', function () {
119
132
120
133
describe ( 'on lost connection' , function ( ) {
121
134
it ( 'emit an error after max retry attempts and do not try to reconnect afterwards' , function ( done ) {
122
- var max_attempts = 4 ;
135
+ var max_attempts = 3 ;
123
136
var options = {
124
137
parser : parser ,
125
138
max_attempts : max_attempts
@@ -138,10 +151,14 @@ describe('connection tests', function () {
138
151
139
152
client . on ( 'error' , function ( err ) {
140
153
if ( / R e d i s c o n n e c t i o n i n b r o k e n s t a t e : m a x i m u m c o n n e c t i o n a t t e m p t s .* ?e x c e e d e d ./ . test ( err . message ) ) {
141
- setTimeout ( function ( ) {
154
+ process . nextTick ( function ( ) { // End is called after the error got emitted
142
155
assert . strictEqual ( calls , max_attempts - 1 ) ;
156
+ assert . strictEqual ( client . emitted_end , true ) ;
157
+ assert . strictEqual ( client . connected , false ) ;
158
+ assert . strictEqual ( client . ready , false ) ;
159
+ assert . strictEqual ( client . closing , true ) ;
143
160
done ( ) ;
144
- } , 500 ) ;
161
+ } ) ;
145
162
}
146
163
} ) ;
147
164
} ) ;
@@ -167,11 +184,15 @@ describe('connection tests', function () {
167
184
168
185
client . on ( 'error' , function ( err ) {
169
186
if ( / R e d i s c o n n e c t i o n i n b r o k e n s t a t e : c o n n e c t i o n t i m e o u t .* ?e x c e e d e d ./ . test ( err . message ) ) {
170
- setTimeout ( function ( ) {
187
+ process . nextTick ( function ( ) { // End is called after the error got emitted
188
+ assert . strictEqual ( client . emitted_end , true ) ;
189
+ assert . strictEqual ( client . connected , false ) ;
190
+ assert . strictEqual ( client . ready , false ) ;
191
+ assert . strictEqual ( client . closing , true ) ;
171
192
assert . strictEqual ( client . retry_totaltime , connect_timeout ) ;
172
193
assert . strictEqual ( time , connect_timeout ) ;
173
194
done ( ) ;
174
- } , 500 ) ;
195
+ } ) ;
175
196
}
176
197
} ) ;
177
198
} ) ;
@@ -190,7 +211,7 @@ describe('connection tests', function () {
190
211
client . on ( 'reconnecting' , function ( params ) {
191
212
client . end ( true ) ;
192
213
assert . strictEqual ( params . times_connected , 1 ) ;
193
- setTimeout ( done , 100 ) ;
214
+ setTimeout ( done , 5 ) ;
194
215
} ) ;
195
216
} ) ;
196
217
@@ -291,7 +312,6 @@ describe('connection tests', function () {
291
312
292
313
it ( 'emit an error after the socket timeout exceeded the connect_timeout time' , function ( done ) {
293
314
var connect_timeout = 500 ; // in ms
294
- var time = Date . now ( ) ;
295
315
client = redis . createClient ( {
296
316
parser : parser ,
297
317
// Auto detect ipv4 and use non routable ip to trigger the timeout
@@ -308,17 +328,18 @@ describe('connection tests', function () {
308
328
throw new Error ( 'No reconnect, since no connection was ever established' ) ;
309
329
} ) ;
310
330
331
+ var time = Date . now ( ) ;
311
332
client . on ( 'error' , function ( err ) {
312
333
if ( err . code === 'ENETUNREACH' ) { // The test is run without a internet connection. Pretent it works
313
334
return done ( ) ;
314
335
}
315
336
assert ( / R e d i s c o n n e c t i o n i n b r o k e n s t a t e : c o n n e c t i o n t i m e o u t .* ?e x c e e d e d ./ . test ( err . message ) ) ;
316
337
// The code execution on windows is very slow at times
317
- var add = process . platform !== 'win32' ? 25 : 125 ;
338
+ var add = process . platform !== 'win32' ? 15 : 200 ;
318
339
var now = Date . now ( ) ;
319
340
assert ( now - time < connect_timeout + add , 'The real timeout time should be below ' + ( connect_timeout + add ) + 'ms but is: ' + ( now - time ) ) ;
320
341
// Timers sometimes trigger early (e.g. 1ms to early)
321
- assert ( now - time >= connect_timeout - 3 , 'The real timeout time should be above ' + connect_timeout + 'ms, but it is: ' + ( now - time ) ) ;
342
+ assert ( now - time >= connect_timeout - 5 , 'The real timeout time should be above ' + connect_timeout + 'ms, but it is: ' + ( now - time ) ) ;
322
343
done ( ) ;
323
344
} ) ;
324
345
} ) ;
@@ -546,7 +567,7 @@ describe('connection tests', function () {
546
567
} ) ;
547
568
}
548
569
549
- it ( 'redis still loading <= 1000ms ' , function ( done ) {
570
+ it ( 'redis still loading <= 500 ' , function ( done ) {
550
571
client = redis . createClient . apply ( null , args ) ;
551
572
var tmp = client . info . bind ( client ) ;
552
573
var end = helper . callFuncAfter ( done , 3 ) ;
@@ -568,9 +589,9 @@ describe('connection tests', function () {
568
589
} ;
569
590
client . on ( 'ready' , function ( ) {
570
591
var rest = Date . now ( ) - time ;
571
- assert ( rest >= 498 , 'Rest should be equal or above 500 ms but is: ' + rest ) ; // setTimeout might trigger early
592
+ assert ( rest >= 495 , 'Rest should be equal or above 500 ms but is: ' + rest ) ; // setTimeout might trigger early
572
593
// Be on the safe side and accept 200ms above the original value
573
- assert ( rest - 200 < 500 , 'Rest - 200 should be below 500 ms but is: ' + ( rest - 200 ) ) ;
594
+ assert ( rest - 250 < 500 , 'Rest - 250 should be below 500 ms but is: ' + ( rest - 250 ) ) ;
574
595
assert ( delayed ) ;
575
596
end ( ) ;
576
597
} ) ;
@@ -601,7 +622,7 @@ describe('connection tests', function () {
601
622
var rest = Date . now ( ) - time ;
602
623
assert ( rest >= 998 , '`rest` should be equal or above 1000 ms but is: ' + rest ) ; // setTimeout might trigger early
603
624
// Be on the safe side and accept 200ms above the original value
604
- assert ( rest - 200 < 1000 , '`rest` - 200 should be below 1000 ms but is: ' + ( rest - 200 ) ) ;
625
+ assert ( rest - 250 < 1000 , '`rest` - 250 should be below 1000 ms but is: ' + ( rest - 250 ) ) ;
605
626
assert ( delayed ) ;
606
627
end ( ) ;
607
628
} ) ;
0 commit comments