@@ -559,7 +559,7 @@ describe('ChannelConnection', () => {
559
559
} )
560
560
561
561
describe ( '.__handleOngoingRequestsNumberChange()' , ( ) => {
562
- it ( 'should call channel.stopReceiveTimeout when requets number equals to 0' , ( ) => {
562
+ it ( 'should call channel.stopReceiveTimeout when requests number equals to 0' , ( ) => {
563
563
const channel = {
564
564
stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
565
565
startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
@@ -571,7 +571,7 @@ describe('ChannelConnection', () => {
571
571
expect ( channel . stopReceiveTimeout ) . toHaveBeenCalledTimes ( 1 )
572
572
} )
573
573
574
- it ( 'should not call channel.startReceiveTimeout when requets number equals to 0' , ( ) => {
574
+ it ( 'should not call channel.startReceiveTimeout when requests number equals to 0' , ( ) => {
575
575
const channel = {
576
576
stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
577
577
startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
@@ -585,7 +585,7 @@ describe('ChannelConnection', () => {
585
585
586
586
it . each ( [
587
587
[ 1 ] , [ 2 ] , [ 3 ] , [ 5 ] , [ 8 ] , [ 13 ] , [ 3000 ]
588
- ] ) ( 'should call channel.startReceiveTimeout when requets number equals to %d' , ( requests ) => {
588
+ ] ) ( 'should call channel.startReceiveTimeout when requests number equals to %d' , ( requests ) => {
589
589
const channel = {
590
590
stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
591
591
startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
@@ -599,7 +599,7 @@ describe('ChannelConnection', () => {
599
599
600
600
it . each ( [
601
601
[ 1 ] , [ 2 ] , [ 3 ] , [ 5 ] , [ 8 ] , [ 13 ] , [ 3000 ]
602
- ] ) ( 'should not call channel.stopReceiveTimeout when requets number equals to %d' , ( requests ) => {
602
+ ] ) ( 'should not call channel.stopReceiveTimeout when requests number equals to %d' , ( requests ) => {
603
603
const channel = {
604
604
stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
605
605
startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
@@ -610,6 +610,68 @@ describe('ChannelConnection', () => {
610
610
611
611
expect ( channel . stopReceiveTimeout ) . toHaveBeenCalledTimes ( 0 )
612
612
} )
613
+
614
+ it . each ( [
615
+ [ 0 ] , [ 1 ] , [ 2 ] , [ 3 ] , [ 5 ] , [ 8 ] , [ 13 ] , [ 3000 ]
616
+ ] ) ( 'should not call channel.stopReceiveTimeout or startReceiveTimeout when requests number equals to %d and connection is idle' , ( requests ) => {
617
+ const channel = {
618
+ stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
619
+ startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
620
+ }
621
+ const protocol = {
622
+ queueObserverIfProtocolIsNotBroken : jest . fn ( ( ) => { } )
623
+ }
624
+ const connection = spyOnConnectionChannel ( { channel, protocolSupplier : ( ) => protocol } )
625
+ connection . _setIdle ( { } )
626
+ channel . stopReceiveTimeout . mockClear ( )
627
+
628
+ connection . _handleOngoingRequestsNumberChange ( requests )
629
+
630
+ expect ( channel . stopReceiveTimeout ) . toHaveBeenCalledTimes ( 0 )
631
+ expect ( channel . startReceiveTimeout ) . toHaveBeenCalledTimes ( 0 )
632
+ } )
633
+
634
+ it . each ( [
635
+ [ 1 ] , [ 2 ] , [ 3 ] , [ 5 ] , [ 8 ] , [ 13 ] , [ 3000 ]
636
+ ] ) ( 'should call channel.startReceiveTimeout when requests number equals to %d and connection is not idle anymore' , ( requests ) => {
637
+ const channel = {
638
+ stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
639
+ startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
640
+ }
641
+ const protocol = {
642
+ queueObserverIfProtocolIsNotBroken : jest . fn ( ( ) => { } ) ,
643
+ updateCurrentObserver : jest . fn ( ( ) => { } )
644
+ }
645
+ const connection = spyOnConnectionChannel ( { channel, protocolSupplier : ( ) => protocol } )
646
+ connection . _setIdle ( { } )
647
+ connection . _unsetIdle ( )
648
+ channel . stopReceiveTimeout . mockClear ( )
649
+
650
+ connection . _handleOngoingRequestsNumberChange ( requests )
651
+
652
+ expect ( channel . stopReceiveTimeout ) . toHaveBeenCalledTimes ( 0 )
653
+ expect ( channel . startReceiveTimeout ) . toHaveBeenCalledTimes ( 1 )
654
+ } )
655
+
656
+ it ( 'should call channel.stopReceiveTimeout when requests number equals to 0 and connection is not idle anymore' , ( ) => {
657
+ const channel = {
658
+ stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' ) ,
659
+ startReceiveTimeout : jest . fn ( ) . mockName ( 'startReceiveTimeout' )
660
+ }
661
+ const protocol = {
662
+ queueObserverIfProtocolIsNotBroken : jest . fn ( ( ) => { } ) ,
663
+ updateCurrentObserver : jest . fn ( ( ) => { } )
664
+ }
665
+ const connection = spyOnConnectionChannel ( { channel, protocolSupplier : ( ) => protocol } )
666
+ connection . _setIdle ( { } )
667
+ connection . _unsetIdle ( )
668
+ channel . stopReceiveTimeout . mockClear ( )
669
+
670
+ connection . _handleOngoingRequestsNumberChange ( 0 )
671
+
672
+ expect ( channel . stopReceiveTimeout ) . toHaveBeenCalledTimes ( 1 )
673
+ expect ( channel . startReceiveTimeout ) . toHaveBeenCalledTimes ( 0 )
674
+ } )
613
675
} )
614
676
615
677
describe ( '.resetAndFlush()' , ( ) => {
@@ -1181,6 +1243,44 @@ describe('ChannelConnection', () => {
1181
1243
} )
1182
1244
1183
1245
describe ( '.hasOngoingObservableRequests()' , ( ) => {
1246
+ it ( 'should return false if connection is idle' , ( ) => {
1247
+ const protocol = {
1248
+ hasOngoingObservableRequests : jest . fn ( ( ) => true ) ,
1249
+ queueObserverIfProtocolIsNotBroken : jest . fn ( ( ) => { } )
1250
+ }
1251
+ const channel = {
1252
+ stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' )
1253
+ }
1254
+
1255
+ const connection = spyOnConnectionChannel ( { protocolSupplier : ( ) => protocol , channel } )
1256
+ connection . _setIdle ( { } )
1257
+
1258
+ const result = connection . hasOngoingObservableRequests ( )
1259
+
1260
+ expect ( result ) . toBe ( false )
1261
+ expect ( protocol . hasOngoingObservableRequests ) . not . toBeCalledWith ( )
1262
+ } )
1263
+
1264
+ it ( 'should redirect request to the protocol when connection is not idle anymore' , ( ) => {
1265
+ const protocol = {
1266
+ hasOngoingObservableRequests : jest . fn ( ( ) => true ) ,
1267
+ queueObserverIfProtocolIsNotBroken : jest . fn ( ( ) => { } ) ,
1268
+ updateCurrentObserver : jest . fn ( ( ) => { } )
1269
+ }
1270
+ const channel = {
1271
+ stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' )
1272
+ }
1273
+
1274
+ const connection = spyOnConnectionChannel ( { protocolSupplier : ( ) => protocol , channel } )
1275
+ connection . _setIdle ( { } )
1276
+ connection . _unsetIdle ( )
1277
+
1278
+ const result = connection . hasOngoingObservableRequests ( )
1279
+
1280
+ expect ( result ) . toBe ( true )
1281
+ expect ( protocol . hasOngoingObservableRequests ) . toBeCalledWith ( )
1282
+ } )
1283
+
1184
1284
it ( 'should call redirect request to the protocol' , ( ) => {
1185
1285
const protocol = {
1186
1286
hasOngoingObservableRequests : jest . fn ( ( ) => true )
@@ -1195,6 +1295,41 @@ describe('ChannelConnection', () => {
1195
1295
} )
1196
1296
} )
1197
1297
1298
+ describe ( '._setIdle()' , ( ) => {
1299
+ it ( 'should stop receive timeout and enqueue observer' , ( ) => {
1300
+ const protocol = {
1301
+ queueObserverIfProtocolIsNotBroken : jest . fn ( ( ) => { } )
1302
+ }
1303
+ const channel = {
1304
+ stopReceiveTimeout : jest . fn ( ) . mockName ( 'stopReceiveTimeout' )
1305
+ }
1306
+ const observer = {
1307
+ onComplete : ( ) => { }
1308
+ }
1309
+
1310
+ const connection = spyOnConnectionChannel ( { protocolSupplier : ( ) => protocol , channel } )
1311
+
1312
+ connection . _setIdle ( observer )
1313
+
1314
+ expect ( channel . stopReceiveTimeout ) . toBeCalledTimes ( 1 )
1315
+ expect ( protocol . queueObserverIfProtocolIsNotBroken ) . toBeCalledWith ( observer )
1316
+ } )
1317
+ } )
1318
+
1319
+ describe ( '._unsetIdle()' , ( ) => {
1320
+ it ( 'should update current observer' , ( ) => {
1321
+ const protocol = {
1322
+ updateCurrentObserver : jest . fn ( ( ) => { } )
1323
+ }
1324
+
1325
+ const connection = spyOnConnectionChannel ( { protocolSupplier : ( ) => protocol } )
1326
+
1327
+ connection . _unsetIdle ( )
1328
+
1329
+ expect ( protocol . updateCurrentObserver ) . toBeCalledTimes ( 1 )
1330
+ } )
1331
+ } )
1332
+
1198
1333
function spyOnConnectionChannel ( {
1199
1334
channel,
1200
1335
errorHandler,
0 commit comments