1
1
import {
2
2
DEFAULT_RETRY_DELAY_BASE ,
3
- THROTTLING_RETRY_DELAY_BASE
3
+ THROTTLING_RETRY_DELAY_BASE ,
4
+ INITIAL_RETRY_TOKENS
4
5
} from "./constants" ;
5
6
import { isThrottlingError } from "@aws-sdk/service-error-classification" ;
6
7
import { defaultDelayDecider } from "./delayDecider" ;
@@ -154,12 +155,16 @@ describe("defaultStrategy", () => {
154
155
describe ( "retryQuota init" , ( ) => {
155
156
it ( "sets getDefaultRetryQuota if options is undefined" , ( ) => {
156
157
const retryStrategy = new StandardRetryStrategy ( maxAttempts ) ;
157
- expect ( retryStrategy [ "retryQuota" ] ) . toBe ( getDefaultRetryQuota ( ) ) ;
158
+ expect ( retryStrategy [ "retryQuota" ] ) . toBe (
159
+ getDefaultRetryQuota ( INITIAL_RETRY_TOKENS )
160
+ ) ;
158
161
} ) ;
159
162
160
163
it ( "sets getDefaultRetryQuota if options.delayDecider undefined" , ( ) => {
161
164
const retryStrategy = new StandardRetryStrategy ( maxAttempts , { } ) ;
162
- expect ( retryStrategy [ "retryQuota" ] ) . toBe ( getDefaultRetryQuota ( ) ) ;
165
+ expect ( retryStrategy [ "retryQuota" ] ) . toBe (
166
+ getDefaultRetryQuota ( INITIAL_RETRY_TOKENS )
167
+ ) ;
163
168
} ) ;
164
169
165
170
it ( "sets options.retryQuota if defined" , ( ) => {
@@ -253,27 +258,29 @@ describe("defaultStrategy", () => {
253
258
describe ( "retryQuota" , ( ) => {
254
259
describe ( "hasRetryTokens" , ( ) => {
255
260
it ( "not called on successful operation" , async ( ) => {
256
- const { hasRetryTokens } = getDefaultRetryQuota ( ) ;
261
+ const { hasRetryTokens } = getDefaultRetryQuota ( INITIAL_RETRY_TOKENS ) ;
257
262
await mockSuccessfulOperation ( maxAttempts ) ;
258
263
expect ( hasRetryTokens ) . not . toHaveBeenCalled ( ) ;
259
264
} ) ;
260
265
261
266
it ( "called once in case of single failure" , async ( ) => {
262
- const { hasRetryTokens } = getDefaultRetryQuota ( ) ;
267
+ const { hasRetryTokens } = getDefaultRetryQuota ( INITIAL_RETRY_TOKENS ) ;
263
268
await mockSuccessAfterOneFail ( maxAttempts ) ;
264
269
expect ( hasRetryTokens ) . toHaveBeenCalledTimes ( 1 ) ;
265
270
} ) ;
266
271
267
272
it ( "called once on each retry request" , async ( ) => {
268
- const { hasRetryTokens } = getDefaultRetryQuota ( ) ;
273
+ const { hasRetryTokens } = getDefaultRetryQuota ( INITIAL_RETRY_TOKENS ) ;
269
274
await mockFailedOperation ( maxAttempts ) ;
270
275
expect ( hasRetryTokens ) . toHaveBeenCalledTimes ( maxAttempts - 1 ) ;
271
276
} ) ;
272
277
} ) ;
273
278
274
279
describe ( "releaseRetryTokens" , ( ) => {
275
280
it ( "called once without param on successful operation" , async ( ) => {
276
- const { releaseRetryTokens } = getDefaultRetryQuota ( ) ;
281
+ const { releaseRetryTokens } = getDefaultRetryQuota (
282
+ INITIAL_RETRY_TOKENS
283
+ ) ;
277
284
await mockSuccessfulOperation ( maxAttempts ) ;
278
285
expect ( releaseRetryTokens ) . toHaveBeenCalledTimes ( 1 ) ;
279
286
expect ( releaseRetryTokens ) . toHaveBeenCalledWith ( undefined ) ;
@@ -284,7 +291,7 @@ describe("defaultStrategy", () => {
284
291
const {
285
292
releaseRetryTokens,
286
293
retrieveRetryTokens
287
- } = getDefaultRetryQuota ( ) ;
294
+ } = getDefaultRetryQuota ( INITIAL_RETRY_TOKENS ) ;
288
295
( retrieveRetryTokens as jest . Mock ) . mockReturnValueOnce ( retryTokens ) ;
289
296
290
297
await mockSuccessAfterOneFail ( maxAttempts ) ;
@@ -299,7 +306,7 @@ describe("defaultStrategy", () => {
299
306
const {
300
307
releaseRetryTokens,
301
308
retrieveRetryTokens
302
- } = getDefaultRetryQuota ( ) ;
309
+ } = getDefaultRetryQuota ( INITIAL_RETRY_TOKENS ) ;
303
310
304
311
( retrieveRetryTokens as jest . Mock )
305
312
. mockReturnValueOnce ( retryTokensFirst )
@@ -311,27 +318,35 @@ describe("defaultStrategy", () => {
311
318
} ) ;
312
319
313
320
it ( "not called on unsuccessful operation" , async ( ) => {
314
- const { releaseRetryTokens } = getDefaultRetryQuota ( ) ;
321
+ const { releaseRetryTokens } = getDefaultRetryQuota (
322
+ INITIAL_RETRY_TOKENS
323
+ ) ;
315
324
await mockFailedOperation ( maxAttempts ) ;
316
325
expect ( releaseRetryTokens ) . not . toHaveBeenCalled ( ) ;
317
326
} ) ;
318
327
} ) ;
319
328
320
329
describe ( "retrieveRetryTokens" , ( ) => {
321
330
it ( "not called on successful operation" , async ( ) => {
322
- const { retrieveRetryTokens } = getDefaultRetryQuota ( ) ;
331
+ const { retrieveRetryTokens } = getDefaultRetryQuota (
332
+ INITIAL_RETRY_TOKENS
333
+ ) ;
323
334
await mockSuccessfulOperation ( maxAttempts ) ;
324
335
expect ( retrieveRetryTokens ) . not . toHaveBeenCalled ( ) ;
325
336
} ) ;
326
337
327
338
it ( "called once in case of single failure" , async ( ) => {
328
- const { retrieveRetryTokens } = getDefaultRetryQuota ( ) ;
339
+ const { retrieveRetryTokens } = getDefaultRetryQuota (
340
+ INITIAL_RETRY_TOKENS
341
+ ) ;
329
342
await mockSuccessAfterOneFail ( maxAttempts ) ;
330
343
expect ( retrieveRetryTokens ) . toHaveBeenCalledTimes ( 1 ) ;
331
344
} ) ;
332
345
333
346
it ( "called once on each retry request" , async ( ) => {
334
- const { retrieveRetryTokens } = getDefaultRetryQuota ( ) ;
347
+ const { retrieveRetryTokens } = getDefaultRetryQuota (
348
+ INITIAL_RETRY_TOKENS
349
+ ) ;
335
350
await mockFailedOperation ( maxAttempts ) ;
336
351
expect ( retrieveRetryTokens ) . toHaveBeenCalledTimes ( maxAttempts - 1 ) ;
337
352
} ) ;
@@ -372,7 +387,7 @@ describe("defaultStrategy", () => {
372
387
hasRetryTokens,
373
388
retrieveRetryTokens,
374
389
releaseRetryTokens
375
- } = getDefaultRetryQuota ( ) ;
390
+ } = getDefaultRetryQuota ( INITIAL_RETRY_TOKENS ) ;
376
391
( hasRetryTokens as jest . Mock ) . mockReturnValueOnce ( false ) ;
377
392
378
393
const mockError = new Error ( ) ;
0 commit comments