@@ -93,8 +93,12 @@ const BACKGROUND_EXECUTE_MS_HTTP = 1000
9393class MockHttpTransport extends HttpTransport < HttpTransportTypes > {
9494 backgroundExecuteCalls = 0
9595
96- constructor ( private callSuper = false ) {
96+ constructor (
97+ private callSuper = false ,
98+ backgroundSleepMs ?: number ,
99+ ) {
97100 super ( {
101+ backgroundSleepMs,
98102 prepareRequests : ( params ) => ( {
99103 params,
100104 request : {
@@ -203,6 +207,45 @@ test.serial('sends request to DP and returns response', async (t) => {
203207 } )
204208} )
205209
210+ test . serial (
211+ 'backgroundSleepMs delays data provider requests until the configured sleep has elapsed on the fake clock' ,
212+ async ( t ) => {
213+ const bgSleepMs = 2_000
214+ const fromSymbol = 'BGSLEEPCHK'
215+ let dataProviderRequests = 0
216+
217+ axiosMock
218+ . onPost ( URL + endpoint , {
219+ pairs : [ { base : fromSymbol , quote : to } ] ,
220+ } )
221+ . reply ( ( ) => {
222+ dataProviderRequests ++
223+ return [ 200 , { } ]
224+ } )
225+
226+ const adapter = new Adapter ( {
227+ name : 'TEST' ,
228+ defaultEndpoint : 'test' ,
229+ endpoints : [
230+ new AdapterEndpoint ( {
231+ name : 'test' ,
232+ inputParameters,
233+ transport : new MockHttpTransport ( true , bgSleepMs ) ,
234+ } ) ,
235+ ] ,
236+ } )
237+
238+ const testAdapter = await TestAdapter . startWithMockedCache ( adapter , t . context )
239+ await testAdapter . request ( { from : fromSymbol , to } )
240+
241+ t . is ( dataProviderRequests , 0 )
242+ await runAllUntilTime ( t . context . clock , bgSleepMs / 2 )
243+ t . is ( dataProviderRequests , 0 )
244+ await runAllUntilTime ( t . context . clock , bgSleepMs )
245+ t . is ( dataProviderRequests , 1 )
246+ } ,
247+ )
248+
206249test . serial (
207250 'per minute rate limit of 4 with one batch transport results in a call every 15s' ,
208251 async ( t ) => {
0 commit comments