Skip to content

Commit 8a1c222

Browse files
committed
test: retryQuota.hasRetryTokens false after first retry
1 parent fb44543 commit 8a1c222

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

packages/middleware-retry/src/defaultStrategy.spec.ts

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,45 @@ describe("defaultStrategy", () => {
382382
);
383383
});
384384

385-
it("when retryQuota.hasRetryTokens returns false", async () => {
386-
const {
387-
hasRetryTokens,
388-
retrieveRetryTokens,
389-
releaseRetryTokens
390-
} = getDefaultRetryQuota(INITIAL_RETRY_TOKENS);
391-
(hasRetryTokens as jest.Mock).mockReturnValueOnce(false);
385+
describe("when retryQuota.hasRetryTokens returns false", () => {
386+
it("in the first request", async () => {
387+
const {
388+
hasRetryTokens,
389+
retrieveRetryTokens,
390+
releaseRetryTokens
391+
} = getDefaultRetryQuota(INITIAL_RETRY_TOKENS);
392+
(hasRetryTokens as jest.Mock).mockReturnValueOnce(false);
392393

393-
const mockError = new Error();
394-
await mockFailedOperation(maxAttempts, { mockError });
394+
const mockError = new Error();
395+
await mockFailedOperation(maxAttempts, { mockError });
396+
397+
expect(hasRetryTokens).toHaveBeenCalledTimes(1);
398+
expect(hasRetryTokens).toHaveBeenCalledWith(mockError);
399+
expect(retrieveRetryTokens).not.toHaveBeenCalled();
400+
expect(releaseRetryTokens).not.toHaveBeenCalled();
401+
});
395402

396-
expect(hasRetryTokens).toHaveBeenCalledTimes(1);
397-
expect(hasRetryTokens).toHaveBeenCalledWith(mockError);
398-
expect(retrieveRetryTokens).not.toHaveBeenCalled();
399-
expect(releaseRetryTokens).not.toHaveBeenCalled();
403+
it("after the first retry", async () => {
404+
const {
405+
hasRetryTokens,
406+
retrieveRetryTokens,
407+
releaseRetryTokens
408+
} = getDefaultRetryQuota(INITIAL_RETRY_TOKENS);
409+
(hasRetryTokens as jest.Mock)
410+
.mockReturnValueOnce(true)
411+
.mockReturnValueOnce(false);
412+
413+
const mockError = new Error();
414+
await mockFailedOperation(maxAttempts, { mockError });
415+
416+
expect(hasRetryTokens).toHaveBeenCalledTimes(2);
417+
[1, 2].forEach(n => {
418+
expect(hasRetryTokens).toHaveBeenNthCalledWith(n, mockError);
419+
});
420+
expect(retrieveRetryTokens).toHaveBeenCalledTimes(1);
421+
expect(retrieveRetryTokens).toHaveBeenCalledWith(mockError);
422+
expect(releaseRetryTokens).not.toHaveBeenCalled();
423+
});
400424
});
401425
});
402426
});

0 commit comments

Comments
 (0)