-
Notifications
You must be signed in to change notification settings - Fork 3
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
Use exponential backoff for s3 503 error #46
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
02e68f6
Use exponential backoff for se 503 error
tuliren e38b28d
Add unit tests
tuliren 908f8d7
Update package
tuliren 46fb00a
Depend on p-retry
tuliren e07bffc
Revert "Depend on p-retry"
tuliren 94354cf
Unify tests
tuliren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as core from '@actions/core'; | ||
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'; | ||
import fetch, { Response } from 'cross-fetch'; | ||
|
||
import { uploadFileWithSignedUrl } from '../../../src/plugins/staticHosting/helpers'; | ||
|
||
jest.mock('cross-fetch', () => jest.fn()); | ||
const mockFetch = fetch as jest.MockedFunction<typeof fetch>; | ||
|
||
jest.mock('@actions/core'); | ||
const mockCore = core as jest.Mocked<typeof core>; | ||
|
||
describe('uploadFileWithSignedUrl', function () { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('when there is no error', function () { | ||
it('uploads the file with one fetch call', async () => { | ||
mockFetch.mockResolvedValue({ ok: true } as Response); | ||
await uploadFileWithSignedUrl('https://localhost', {}, 'object-key', 'package.json'); | ||
expect(mockFetch).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('when there is 503 error', function () { | ||
const response503 = { ok: false, status: 503, statusText: 'Slow down' } as Response; | ||
|
||
beforeEach(() => { | ||
mockFetch | ||
.mockResolvedValueOnce(response503) | ||
.mockResolvedValueOnce(response503) | ||
.mockResolvedValue({ ok: true, status: 204, statusText: 'No content' } as Response); | ||
}); | ||
|
||
it('retries', async () => { | ||
await uploadFileWithSignedUrl('https://localhost', {}, 'object-key', 'package.json'); | ||
expect(mockFetch).toHaveBeenCalledTimes(3); | ||
|
||
const warnings = mockCore.warning.mock.calls; | ||
expect(warnings.length).toEqual(2); | ||
warnings.forEach((warning) => { | ||
expect(warning[0]).toContain('503 error'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should move this setup to a "beforeEach" block to be consistent across different tests within this file.