mirror of
https://github.com/actions/github-script.git
synced 2026-04-07 22:50:04 +00:00
feat: add throttling plugin when retries is configured
This commit is contained in:
parent
60a0d83039
commit
691bd6b113
6 changed files with 370 additions and 36 deletions
|
|
@ -4,7 +4,7 @@ import {getRetryOptions} from '../src/retry-options'
|
|||
|
||||
describe('getRequestOptions', () => {
|
||||
test('retries disabled if retries == 0', async () => {
|
||||
const [retryOptions, requestOptions] = getRetryOptions(
|
||||
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
|
||||
0,
|
||||
[400, 500, 502],
|
||||
[]
|
||||
|
|
@ -14,10 +14,12 @@ describe('getRequestOptions', () => {
|
|||
expect(retryOptions.doNotRetry).toBeFalsy()
|
||||
|
||||
expect(requestOptions?.retries).toBeFalsy()
|
||||
expect(throttlingOptions?.onRateLimit).toBeFalsy()
|
||||
expect(throttlingOptions?.onSecondaryRateLimit).toBeFalsy()
|
||||
})
|
||||
|
||||
test('properties set if retries > 0', async () => {
|
||||
const [retryOptions, requestOptions] = getRetryOptions(
|
||||
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
|
||||
1,
|
||||
[400, 500, 502],
|
||||
[]
|
||||
|
|
@ -27,10 +29,12 @@ describe('getRequestOptions', () => {
|
|||
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])
|
||||
|
||||
expect(requestOptions?.retries).toEqual(1)
|
||||
expect(throttlingOptions?.onRateLimit).toBeDefined()
|
||||
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
|
||||
})
|
||||
|
||||
test('properties set if retries > 0', async () => {
|
||||
const [retryOptions, requestOptions] = getRetryOptions(
|
||||
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
|
||||
1,
|
||||
[400, 500, 502],
|
||||
[]
|
||||
|
|
@ -40,24 +44,36 @@ describe('getRequestOptions', () => {
|
|||
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])
|
||||
|
||||
expect(requestOptions?.retries).toEqual(1)
|
||||
expect(throttlingOptions?.onRateLimit).toBeDefined()
|
||||
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
|
||||
})
|
||||
|
||||
test('retryOptions.doNotRetry not set if exemptStatusCodes isEmpty', async () => {
|
||||
const [retryOptions, requestOptions] = getRetryOptions(1, [], [])
|
||||
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
|
||||
1,
|
||||
[],
|
||||
[]
|
||||
)
|
||||
|
||||
expect(retryOptions.enabled).toBe(true)
|
||||
expect(retryOptions.doNotRetry).toBeUndefined()
|
||||
|
||||
expect(requestOptions?.retries).toEqual(1)
|
||||
expect(throttlingOptions?.onRateLimit).toBeDefined()
|
||||
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
|
||||
})
|
||||
|
||||
test('requestOptions does not override defaults from @actions/github', async () => {
|
||||
const [retryOptions, requestOptions] = getRetryOptions(1, [], {
|
||||
request: {
|
||||
agent: 'default-user-agent'
|
||||
},
|
||||
foo: 'bar'
|
||||
})
|
||||
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
|
||||
1,
|
||||
[],
|
||||
{
|
||||
request: {
|
||||
agent: 'default-user-agent'
|
||||
},
|
||||
foo: 'bar'
|
||||
}
|
||||
)
|
||||
|
||||
expect(retryOptions.enabled).toBe(true)
|
||||
expect(retryOptions.doNotRetry).toBeUndefined()
|
||||
|
|
@ -65,5 +81,8 @@ describe('getRequestOptions', () => {
|
|||
expect(requestOptions?.retries).toEqual(1)
|
||||
expect(requestOptions?.agent).toEqual('default-user-agent')
|
||||
expect(requestOptions?.foo).toBeUndefined() // this should not be in the `options.request` object, but at the same level as `request`
|
||||
|
||||
expect(throttlingOptions?.onRateLimit).toBeDefined()
|
||||
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue