Skip to content

Commit

Permalink
ASAP-361 Adjust parameters to reduce revision errors (#4213)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabiayako authored Mar 22, 2024
1 parent e1c7449 commit 2d60fce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion packages/contentful/src/utils/poll-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ const pollContentful = async <T extends EntrySkeletonType<FieldsType, string>>(
}
}
},
{ minTimeout: 200, maxRetryTime: 8_000 },
{
minTimeout: 200,
maxRetryTime: 60_000,
factor: 2,
randomize: false,
},
);

export const pollContentfulDeliveryApi = async <
Expand Down
18 changes: 14 additions & 4 deletions packages/contentful/test/utils/poll-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ describe('pollContentfulGql', () => {
.fn()
.mockResolvedValueOnce(userDataWithPublishedVersion1)
.mockResolvedValueOnce(userDataWithPublishedVersion1)
.mockResolvedValueOnce(userDataWithPublishedVersion1)
.mockResolvedValueOnce(userDataWithPublishedVersion1)
.mockResolvedValueOnce(userDataWithPublishedVersion1)
.mockResolvedValueOnce(userDataWithPublishedVersion1)
.mockResolvedValueOnce(userDataWithPublishedVersion2);

await pollContentfulGql(2, fetchData, 'users');
expect(fetchData).toHaveBeenCalledTimes(3);
});
expect(fetchData).toHaveBeenCalledTimes(7);
}, 120_000);

test('throws if polling query does not return a value', async () => {
const fetchData = jest.fn().mockResolvedValueOnce({
Expand Down Expand Up @@ -55,12 +59,18 @@ describe('pollContentfulDeliveryApi', () => {
.fn()
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter1)
.mockResolvedValueOnce(entryDataWithPublishedCounter2);

const response = await pollContentfulDeliveryApi(fetchEntry, 2);
expect(fetchEntry).toHaveBeenCalledTimes(3);
expect(fetchEntry).toHaveBeenCalledTimes(9);
expect(response).toEqual(entryDataWithPublishedCounter2);
});
}, 120_000);

test('throws if polling query does not return a value', async () => {
const fetchEntry = jest.fn().mockResolvedValueOnce(null);
Expand Down

0 comments on commit 2d60fce

Please sign in to comment.