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

fix: retries validation #8268

Merged
merged 2 commits into from
Aug 13, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/server/lib/util/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ const isValidBrowserList = (key, browsers) => {
}

const isValidRetriesConfig = (key, value) => {
const isNullOrNumber = isOneOf([_.isNumber, _.isNull])

if (
isNullOrNumber(value)
|| (_.isEqual(_.keys(value), ['runMode', 'openMode']))
&& isNullOrNumber(value.runMode)
&& isNullOrNumber(value.openMode)
) {
const optionalKeys = ['runMode', 'openMode']
const isValidRetryValue = (val) => _.isNull(val) || (Number.isInteger(val) && val >= 0)
const optionalKeysAreValid = (val, k) => optionalKeys.includes(k) && isValidRetryValue(val)

if (isValidRetryValue(value)) {
return true
}

if (_.isObject(value) && _.every(value, optionalKeysAreValid)) {
return true
}

return errMsg(key, value, 'a number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls')
return errMsg(key, value, 'a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls')
JessicaSachs marked this conversation as resolved.
Show resolved Hide resolved
}

const isValidFirefoxGcInterval = (key, value) => {
Expand Down
28 changes: 28 additions & 0 deletions packages/server/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,34 @@ describe('lib/config', () => {
})
})

context('retries', () => {
const retriesError = 'a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls'

// need to keep the const here or it'll get stripped by the build
// eslint-disable-next-line no-unused-vars
const cases = [
[{ retries: null }, 'with null', true],
[{ retries: 3 }, 'when a number', true],
[{ retries: 3.2 }, 'when a float', false],
[{ retries: -1 }, 'with a negative number', false],
[{ retries: true }, 'when true', false],
[{ retries: false }, 'when false', false],
[{ retries: {} }, 'with an empty object', true],
[{ retries: { runMode: 3 } }, 'when runMode is a positive number', true],
[{ retries: { runMode: -1 } }, 'when runMode is a negative number', false],
[{ retries: { openMode: 3 } }, 'when openMode is a positive number', true],
[{ retries: { openMode: -1 } }, 'when openMode is a negative number', false],
[{ retries: { openMode: 3, TypoRunMode: 3 } }, 'when there is an additional unknown key', false],
[{ retries: { openMode: 3, runMode: 3 } }, 'when both runMode and openMode are positive numbers', true],
].forEach(([config, expectation, shouldPass]) => {
it(`${shouldPass ? 'passes' : 'fails'} ${expectation}`, function () {
this.setup(config)

return shouldPass ? this.expectValidationPasses() : this.expectValidationFails(retriesError)
})
})
})

context('firefoxGcInterval', () => {
it('passes if a number', function () {
this.setup({ firefoxGcInterval: 1 })
Expand Down