@@ -13,21 +13,25 @@ defineSuite([
13
13
var originalMaximumRequests ;
14
14
var originalMaximumRequestsPerServer ;
15
15
var originalPriorityHeapLength ;
16
+ var originalRequestsByServer ;
16
17
17
18
beforeAll ( function ( ) {
18
19
originalMaximumRequests = RequestScheduler . maximumRequests ;
19
20
originalMaximumRequestsPerServer = RequestScheduler . maximumRequestsPerServer ;
20
21
originalPriorityHeapLength = RequestScheduler . priorityHeapLength ;
22
+ originalRequestsByServer = RequestScheduler . requestsByServer ;
21
23
} ) ;
22
24
23
25
beforeEach ( function ( ) {
24
26
RequestScheduler . clearForSpecs ( ) ;
27
+ RequestScheduler . requestsByServer = { } ;
25
28
} ) ;
26
29
27
30
afterEach ( function ( ) {
28
31
RequestScheduler . maximumRequests = originalMaximumRequests ;
29
32
RequestScheduler . maximumRequestsPerServer = originalMaximumRequestsPerServer ;
30
33
RequestScheduler . priorityHeapLength = originalPriorityHeapLength ;
34
+ RequestScheduler . requestsByServer = originalRequestsByServer ;
31
35
} ) ;
32
36
33
37
it ( 'request throws when request is undefined' , function ( ) {
@@ -61,13 +65,13 @@ defineSuite([
61
65
} ) ;
62
66
63
67
it ( 'getServer with https' , function ( ) {
64
- var server = RequestScheduler . getServerKey ( 'https://foo.com /1' ) ;
65
- expect ( server ) . toEqual ( 'foo.com :443' ) ;
68
+ var server = RequestScheduler . getServerKey ( 'https://test.invalid /1' ) ;
69
+ expect ( server ) . toEqual ( 'test.invalid :443' ) ;
66
70
} ) ;
67
71
68
72
it ( 'getServer with http' , function ( ) {
69
- var server = RequestScheduler . getServerKey ( 'http://foo.com /1' ) ;
70
- expect ( server ) . toEqual ( 'foo.com :80' ) ;
73
+ var server = RequestScheduler . getServerKey ( 'http://test.invalid /1' ) ;
74
+ expect ( server ) . toEqual ( 'test.invalid :80' ) ;
71
75
} ) ;
72
76
73
77
it ( 'honors maximumRequests' , function ( ) {
@@ -84,7 +88,7 @@ defineSuite([
84
88
85
89
function createRequest ( ) {
86
90
return new Request ( {
87
- url : 'http://foo.com /1' ,
91
+ url : 'http://test.invalid /1' ,
88
92
requestFunction : requestFunction ,
89
93
throttle : true
90
94
} ) ;
@@ -147,7 +151,7 @@ defineSuite([
147
151
return deferred . promise ;
148
152
}
149
153
150
- var url = 'http://foo.com /1' ;
154
+ var url = 'http://test.invalid /1' ;
151
155
var server = RequestScheduler . getServerKey ( url ) ;
152
156
153
157
function createRequest ( ) {
@@ -216,7 +220,7 @@ defineSuite([
216
220
217
221
function createRequest ( priority ) {
218
222
var request = new Request ( {
219
- url : 'http://foo.com /1' ,
223
+ url : 'http://test.invalid /1' ,
220
224
requestFunction : requestFunction ,
221
225
throttle : true ,
222
226
priority : priority
@@ -302,7 +306,7 @@ defineSuite([
302
306
} ) ;
303
307
304
308
it ( 'request goes through immediately when throttle is false' , function ( ) {
305
- var url = 'https://foo.com /1' ;
309
+ var url = 'https://test.invalid /1' ;
306
310
testImmediateRequest ( url , false ) ;
307
311
} ) ;
308
312
@@ -317,7 +321,7 @@ defineSuite([
317
321
318
322
var request = new Request ( {
319
323
throttle : true ,
320
- url : 'https://foo.com /1' ,
324
+ url : 'https://test.invalid /1' ,
321
325
requestFunction : requestFunction
322
326
} ) ;
323
327
expect ( request . state ) . toBe ( RequestState . UNISSUED ) ;
@@ -342,7 +346,7 @@ defineSuite([
342
346
343
347
var request = new Request ( {
344
348
throttle : true ,
345
- url : 'https://foo.com /1' ,
349
+ url : 'https://test.invalid /1' ,
346
350
requestFunction : requestFunction
347
351
} ) ;
348
352
@@ -373,7 +377,7 @@ defineSuite([
373
377
374
378
var request = new Request ( {
375
379
throttle : true ,
376
- url : 'https://foo.com /1' ,
380
+ url : 'https://test.invalid /1' ,
377
381
requestFunction : requestFunction ,
378
382
cancelFunction : cancelFunction
379
383
} ) ;
@@ -409,7 +413,7 @@ defineSuite([
409
413
}
410
414
411
415
var request = new Request ( {
412
- url : 'https://foo.com /1' ,
416
+ url : 'https://test.invalid /1' ,
413
417
requestFunction : requestFunction
414
418
} ) ;
415
419
@@ -442,7 +446,7 @@ defineSuite([
442
446
function createRequest ( priority ) {
443
447
return new Request ( {
444
448
throttle : true ,
445
- url : 'https://foo.com /1' ,
449
+ url : 'https://test.invalid /1' ,
446
450
requestFunction : getRequestFunction ( priority ) ,
447
451
priority : priority
448
452
} ) ;
@@ -477,7 +481,7 @@ defineSuite([
477
481
function createRequest ( priority ) {
478
482
return new Request ( {
479
483
throttle : true ,
480
- url : 'https://foo.com /1' ,
484
+ url : 'https://test.invalid /1' ,
481
485
requestFunction : requestFunction ,
482
486
priorityFunction : getPriorityFunction ( priority )
483
487
} ) ;
@@ -529,7 +533,7 @@ defineSuite([
529
533
function createRequest ( priority ) {
530
534
return new Request ( {
531
535
throttle : true ,
532
- url : 'https://foo.com /1' ,
536
+ url : 'https://test.invalid /1' ,
533
537
requestFunction : requestFunction ,
534
538
priority : priority
535
539
} ) ;
@@ -566,7 +570,7 @@ defineSuite([
566
570
567
571
function createRequest ( throttle ) {
568
572
return new Request ( {
569
- url : 'http://foo.com /1' ,
573
+ url : 'http://test.invalid /1' ,
570
574
requestFunction : requestFunction ,
571
575
throttle : throttle
572
576
} ) ;
@@ -604,7 +608,7 @@ defineSuite([
604
608
605
609
function createRequest ( throttleByServer ) {
606
610
return new Request ( {
607
- url : 'http://foo.com /1' ,
611
+ url : 'http://test.invalid /1' ,
608
612
requestFunction : requestFunction ,
609
613
throttleByServer : throttleByServer
610
614
} ) ;
@@ -637,7 +641,7 @@ defineSuite([
637
641
RequestScheduler . throttleRequests = true ;
638
642
var request = new Request ( {
639
643
throttle : true ,
640
- url : 'https://foo.com /1' ,
644
+ url : 'https://test.invalid /1' ,
641
645
requestFunction : requestFunction
642
646
} ) ;
643
647
var promise = RequestScheduler . request ( request ) ;
@@ -646,7 +650,7 @@ defineSuite([
646
650
RequestScheduler . throttleRequests = false ;
647
651
request = new Request ( {
648
652
throttle : true ,
649
- url : 'https://foo.com /1' ,
653
+ url : 'https://test.invalid /1' ,
650
654
requestFunction : requestFunction
651
655
} ) ;
652
656
promise = RequestScheduler . request ( request ) ;
@@ -669,7 +673,7 @@ defineSuite([
669
673
670
674
function createRequest ( ) {
671
675
return new Request ( {
672
- url : 'https://foo.com /1' ,
676
+ url : 'https://test.invalid /1' ,
673
677
requestFunction : requestFunction
674
678
} ) ;
675
679
}
@@ -708,7 +712,7 @@ defineSuite([
708
712
}
709
713
710
714
var request = new Request ( {
711
- url : 'https://foo.com /1' ,
715
+ url : 'https://test.invalid /1' ,
712
716
requestFunction : requestFunction
713
717
} ) ;
714
718
@@ -806,7 +810,7 @@ defineSuite([
806
810
}
807
811
808
812
var request = new Request ( {
809
- url : 'https://foo.com /1' ,
813
+ url : 'https://test.invalid /1' ,
810
814
requestFunction : requestFunction
811
815
} ) ;
812
816
@@ -839,7 +843,7 @@ defineSuite([
839
843
}
840
844
841
845
var requestToCancel = new Request ( {
842
- url : 'https://foo.com /1' ,
846
+ url : 'https://test.invalid /1' ,
843
847
requestFunction : requestCancelFunction
844
848
} ) ;
845
849
@@ -854,4 +858,29 @@ defineSuite([
854
858
cancelDeferred . resolve ( ) ;
855
859
removeListenerCallback ( ) ;
856
860
} ) ;
861
+
862
+ it ( 'RequestScheduler.requestsByServer allows for custom maximum requests' , function ( ) {
863
+ var promise ;
864
+
865
+ RequestScheduler . requestsByServer [ 'test.invalid:80' ] = 23 ;
866
+
867
+ for ( var i = 0 ; i < 23 ; i ++ ) {
868
+ promise = RequestScheduler . request ( new Request ( {
869
+ url : 'http://test.invalid/1' ,
870
+ throttle : true ,
871
+ throttleByServer : true ,
872
+ requestFunction : function ( ) { return when . defer ( ) ; }
873
+ } ) ) ;
874
+ RequestScheduler . update ( ) ;
875
+ expect ( promise ) . toBeDefined ( ) ;
876
+ }
877
+
878
+ promise = RequestScheduler . request ( new Request ( {
879
+ url : 'http://test.invalid/1' ,
880
+ throttle : true ,
881
+ throttleByServer : true ,
882
+ requestFunction : function ( ) { return when . defer ( ) ; }
883
+ } ) ) ;
884
+ expect ( promise ) . toBeUndefined ( ) ;
885
+ } ) ;
857
886
} ) ;
0 commit comments