From e3e6fa1786f7cd45aaf3a2453fc4e7c8559eb041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 11 Apr 2022 17:49:29 +0300 Subject: [PATCH] fix: increase reqest retries (#25) - Ref. testing-library/eslint-plugin-testing-library#509 --- dist/index.js | 5 +++-- src/github-client.ts | 7 +++++-- test/github-client.test.ts | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 367ad47..7a561cc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5771,7 +5771,8 @@ try { } var GithubClient = class { constructor() { - this.MAX_RETRIES = 5; + this.MAX_RETRIES = 30; + this.RETRY_SEEP_TIME_MS = 1e4; this.octokit = import_github.getOctokit(githubToken); } async requestAndRetry(request) { @@ -5780,7 +5781,7 @@ var GithubClient = class { return await request(); } catch (error2) { core.info(`Request failed. Retrying ${retryCount}/${this.MAX_RETRIES}.`); - await sleep(5e3); + await sleep(this.RETRY_SEEP_TIME_MS); } } return await request(); diff --git a/src/github-client.ts b/src/github-client.ts index 28fc238..30b8caa 100644 --- a/src/github-client.ts +++ b/src/github-client.ts @@ -19,7 +19,10 @@ class GithubClient { private octokit: ReturnType; /** Indicates how many times failed request is retried */ - private MAX_RETRIES = 5; + private MAX_RETRIES = 30; + + /** Indicates how many seconds should be waited before failed request is retried */ + private RETRY_SEEP_TIME_MS = 10000; constructor() { this.octokit = getOctokit(githubToken); @@ -33,7 +36,7 @@ class GithubClient { core.info( `Request failed. Retrying ${retryCount}/${this.MAX_RETRIES}.` ); - await sleep(5000); + await sleep(this.RETRY_SEEP_TIME_MS); } } diff --git a/test/github-client.test.ts b/test/github-client.test.ts index 71b26ab..ab678ff 100644 --- a/test/github-client.test.ts +++ b/test/github-client.test.ts @@ -64,9 +64,9 @@ describe('github-client', () => { expect(onIssueCreated).not.toHaveBeenCalled(); }); - test('should recover from 5x API errors', async () => { - // Request should fail 5 times - times(5)(() => mockApiError.mockReturnValueOnce(true)); + test('should recover from 30x API errors', async () => { + // Request should fail 30 times + times(30)(() => mockApiError.mockReturnValueOnce(true)); mockNoExistingIssues.mockReturnValueOnce(true); jest.useFakeTimers(); @@ -85,14 +85,14 @@ describe('github-client', () => { }); }); - test('should fail request after 6x failures', async () => { - times(6)(() => mockApiError.mockReturnValueOnce(true)); + test('should fail request after 31x failures', async () => { + times(31)(() => mockApiError.mockReturnValueOnce(true)); mockNoExistingIssues.mockReturnValueOnce(true); jest.useFakeTimers(); const request = GithubClient.postResults(body); - await waitFor(() => expect(mockApiError).toHaveBeenCalledTimes(6)); + await waitFor(() => expect(mockApiError).toHaveBeenCalledTimes(31)); jest.useRealTimers(); await expect(request).rejects.toMatchInlineSnapshot(`[HttpError]`);