File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ export default class ChannelConnection extends Connection {
123
123
super ( errorHandler )
124
124
125
125
this . _reseting = false
126
+ this . _resetObservers = [ ]
126
127
this . _id = idGenerator ++
127
128
this . _address = address
128
129
this . _server = { address : address . asHostPort ( ) }
@@ -339,18 +340,24 @@ export default class ChannelConnection extends Connection {
339
340
}
340
341
341
342
_reset ( observer ) {
343
+ this . _resetObservers . push ( observer )
342
344
if ( this . _reseting ) {
343
- observer . onComplete ( )
344
345
return
345
346
}
346
347
this . _reseting = true
348
+
349
+ const notifyFinish = ( notify ) => {
350
+ this . _reseting = false
351
+ const observers = this . _resetObservers
352
+ this . _resetObservers = [ ]
353
+ observers . forEach ( notify )
354
+ }
355
+
347
356
this . _protocol . reset ( {
348
357
onError : error => {
349
- this . _reseting = false
350
- observer . onError ( error )
358
+ notifyFinish ( obs => obs . onError ( error ) )
351
359
} , onComplete : ( ) => {
352
- this . _reseting = false
353
- observer . onComplete ( )
360
+ notifyFinish ( obs => obs . onComplete ( ) )
354
361
}
355
362
} )
356
363
}
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ describe('ChannelConnection', () => {
282
282
connection . _resetOnFailure ( )
283
283
284
284
expect ( protocol . reset ) . toHaveBeenCalledTimes ( 1 )
285
- expect ( protocol . resetFailure ) . toHaveBeenCalledTimes ( 1 )
285
+ expect ( protocol . resetFailure ) . not . toHaveBeenCalled ( )
286
286
} )
287
287
288
288
it ( 'should call protocol.reset() when after a previous reset completed' , ( ) => {
@@ -397,20 +397,23 @@ describe('ChannelConnection', () => {
397
397
}
398
398
399
399
const protocol = {
400
- reset : jest . fn ( ) ,
400
+ reset : jest . fn ( observer => {
401
+ setTimeout ( ( ) => observer . onComplete ( ) , 100 )
402
+ } ) ,
401
403
resetFailure : jest . fn ( )
402
404
}
403
405
const protocolSupplier = ( ) => protocol
404
406
const connection = spyOnConnectionChannel ( { channel, protocolSupplier } )
405
407
406
- // to not block since the reset will never complete
407
- connection . resetAndFlush ( )
408
+ const completeFirstResetAndFlush = connection . resetAndFlush ( )
408
409
409
410
expect ( protocol . reset ) . toHaveBeenCalledTimes ( 1 )
410
411
411
412
await connection . resetAndFlush ( )
412
413
413
414
expect ( protocol . reset ) . toHaveBeenCalledTimes ( 1 )
415
+
416
+ await completeFirstResetAndFlush
414
417
} )
415
418
416
419
it ( 'should call protocol.reset() when after a previous reset completed' , async ( ) => {
You can’t perform that action at this time.
0 commit comments