Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry now checks whether potential retry counts are undefined, rather than boolean, in order to avoid filtering out 0's #2958

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const retryWithBackoff: BaseQueryEnhancer<
5,
((defaultOptions as any) || EMPTY_OPTIONS).maxRetries,
((extraOptions as any) || EMPTY_OPTIONS).maxRetries,
].filter(Boolean)
].filter(x => x !== undefined)
const [maxRetries] = possibleMaxRetries.slice(-1)

const defaultRetryCondition: RetryConditionFunction = (_, __, { attempt }) =>
Expand Down
27 changes: 27 additions & 0 deletions packages/toolkit/src/query/tests/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,33 @@ describe('configuration', () => {
expect(baseBaseQuery).toHaveBeenCalledTimes(4)
})

test('Specifying maxRetries as 0 in RetryOptions prevents retries', async () => {
const baseBaseQuery = jest.fn<
ReturnType<BaseQueryFn>,
Parameters<BaseQueryFn>
>()
baseBaseQuery.mockResolvedValue({ error: 'rejected' })

const baseQuery = retry(baseBaseQuery, { maxRetries: 0 })
const api = createApi({
baseQuery,
endpoints: (build) => ({
q1: build.query({
query: () => {},
}),
}),
})

const storeRef = setupApiStore(api, undefined, {
withoutTestLifecycles: true,
})

storeRef.store.dispatch(api.endpoints.q1.initiate({}))
await loopTimers(2)

expect(baseBaseQuery).toHaveBeenCalledTimes(1)
});

test.skip('RetryOptions only accepts one of maxRetries or retryCondition', () => {
// @ts-expect-error Should complain if both exist at once
const ro: RetryOptions = {
Expand Down