@@ -49,7 +49,7 @@ describe('General', function () {
4949} )
5050
5151describe ( 'Github API best practices' , function ( ) {
52- it ( 'Should not allow more than 1 request concurrently ' , async function ( ) {
52+ it ( 'Should linearize requests ' , async function ( ) {
5353 const octokit = new Octokit ( { throttle : { onAbuseLimit : ( ) => 1 , onRateLimit : ( ) => 1 } } )
5454 const req1 = octokit . request ( 'GET /route1' , {
5555 request : {
@@ -172,6 +172,43 @@ describe('Github API best practices', function () {
172172 expect ( plugin . triggersNotification ( '/repos/:foo/:bar/issues' ) ) . to . equal ( true )
173173 } )
174174
175+ it ( 'Should maintain 2000ms between search requests' , async function ( ) {
176+ const octokit = new Octokit ( {
177+ throttle : {
178+ search : new Bottleneck . Group ( { minTime : 50 } ) ,
179+ onAbuseLimit : ( ) => 1 ,
180+ onRateLimit : ( ) => 1
181+ }
182+ } )
183+
184+ const req1 = octokit . request ( 'GET /search/route1' , {
185+ request : {
186+ responses : [ { status : 201 , headers : { } , data : { } } ]
187+ }
188+ } )
189+ const req2 = octokit . request ( 'GET /route2' , {
190+ request : {
191+ responses : [ { status : 202 , headers : { } , data : { } } ]
192+ }
193+ } )
194+ const req3 = octokit . request ( 'GET /search/route3' , {
195+ request : {
196+ responses : [ { status : 203 , headers : { } , data : { } } ]
197+ }
198+ } )
199+
200+ await Promise . all ( [ req1 , req2 , req3 ] )
201+ expect ( octokit . __requestLog ) . to . deep . equal ( [
202+ 'START GET /route2' ,
203+ 'END GET /route2' ,
204+ 'START GET /search/route1' ,
205+ 'END GET /search/route1' ,
206+ 'START GET /search/route3' ,
207+ 'END GET /search/route3'
208+ ] )
209+ expect ( octokit . __requestTimings [ 4 ] - octokit . __requestTimings [ 2 ] ) . to . be . closeTo ( 50 , 20 )
210+ } )
211+
175212 it ( 'Should optimize throughput rather than maintain ordering' , async function ( ) {
176213 const octokit = new Octokit ( {
177214 throttle : {
0 commit comments