retry-limiter
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -5,2 +5,11 @@ # Changelog | ||
## [3.2.0](https://github.com/gemini-testing/retry-limiter/compare/v3.1.1...v3.2.0) (2019-07-03) | ||
### Features | ||
* add option 'disableRetriesOnFail' ([e6e59be](https://github.com/gemini-testing/retry-limiter/commit/e6e59be)) | ||
### [3.1.1](https://github.com/gemini-testing/retry-limiter/compare/v3.1.0...v3.1.1) (2019-06-26) | ||
@@ -7,0 +16,0 @@ |
'use strict'; | ||
const _ = require('lodash'); | ||
const ConfigDecorator = require('./lib/config-decorator'); | ||
const ConfigDecorator = require('./lib/gemini-config-decorator'); | ||
const parseOpts = require('./lib/plugin-opts'); | ||
@@ -15,4 +15,3 @@ const RetryLimiter = require('./lib/retry-limiter'); | ||
const retryRuleAfterLimit = (data) => typeof data.equal === 'undefined' && data.retriesLeft > 0; | ||
const configDecorator = ConfigDecorator.create(gemini.config, retryRuleAfterLimit); | ||
const configDecorator = ConfigDecorator.create(gemini.config); | ||
@@ -19,0 +18,0 @@ let retryLimiter; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const RetryLimiter = require('./lib/retry-limiter'); | ||
const logger = require('./lib/logger'); | ||
@@ -18,4 +19,3 @@ module.exports = (hermione, opts) => { | ||
const retryRuleAfterLimit = () => false; | ||
const configDecorator = ConfigDecorator.create(hermione.config, retryRuleAfterLimit); | ||
const configDecorator = ConfigDecorator.create(hermione.config); | ||
@@ -39,2 +39,7 @@ let retryLimiter; | ||
}); | ||
if (Number.isFinite(opts.setRetriesOnTestFail)) { | ||
logger.info(`will set retries to ${opts.setRetriesOnTestFail} after the first failed test`); | ||
hermione.once(hermione.events.TEST_FAIL, () => configDecorator.setRetries(opts.setRetriesOnTestFail)); | ||
} | ||
}; |
'use strict'; | ||
module.exports = class ConfigDecorator { | ||
static create(config, retryRule) { | ||
return new ConfigDecorator(config, retryRule); | ||
static create(config) { | ||
return new ConfigDecorator(config); | ||
} | ||
constructor(config, retryRule) { | ||
constructor(config) { | ||
this._config = config; | ||
this._retryRule = retryRule; | ||
this._disabledRetries = false; | ||
} | ||
disableRetries() { | ||
this._config.getBrowserIds().forEach((browserId) => { | ||
this._config.forBrowser(browserId).shouldRetry = this._retryRule; | ||
setRetries(retriesCount) { | ||
!this._disabledRetries && this._config.getBrowserIds().forEach((browserId) => { | ||
const browserConfig = this._config.forBrowser(browserId); | ||
browserConfig.shouldRetry = ({retriesLeft}) => { | ||
return browserConfig.retry - retriesLeft < retriesCount; | ||
}; | ||
}); | ||
if (!retriesCount) { | ||
this._disabledRetries = true; | ||
} | ||
} | ||
disableRetries() { | ||
this.setRetries(0); | ||
} | ||
}; |
@@ -28,2 +28,8 @@ 'use strict'; | ||
validate: (value) => !inRange(value, 0, 1) && thr('Option "limit" must be a number in a range from 0 to 1') | ||
}), | ||
setRetriesOnTestFail: option({ | ||
defaultValue: Infinity, | ||
parseEnv: Number, | ||
parseCli: Number, | ||
validate: (value) => !isNonNegativeInteger(value) && value !== Infinity && thr('Option "setRetriesOnTestFail" must be a non negative integer or "Infinity"') | ||
}) | ||
@@ -40,1 +46,5 @@ }), {envPrefix: ENV_PREFIX, cliPrefix: CLI_PREFIX}); | ||
} | ||
function isNonNegativeInteger(value) { | ||
return value >= 0 && Number.isInteger(value); | ||
} |
'use strict'; | ||
const logger = require('./logger'); | ||
module.exports = class RetryLimiter { | ||
@@ -10,3 +12,3 @@ static create(limit, totalTestsCount) { | ||
this._limitTestsCount = Math.ceil(limit * totalTestsCount); | ||
console.info(`retry-limiter: with limit ${limit} will stop retrying tests after ${this._limitTestsCount} failed tests`); | ||
logger.info(`with limit ${limit} will stop retrying tests after ${this._limitTestsCount} retries`); | ||
@@ -13,0 +15,0 @@ this._retriedTestsCount = 0; |
{ | ||
"name": "retry-limiter", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Plugin for gemini and hermione to disable retries at runtime", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -25,2 +25,3 @@ # retry-limiter [![Build Status](https://travis-ci.org/gemini-testing/retry-limiter.svg?branch=master)](https://travis-ci.org/gemini-testing/retry-limiter) | ||
* **limit** (optional) `Number` – number in range from 0 to 1; if retries count to a total number of tests exceed the specified limit all next tests will be run without retries; default `1`. | ||
* **setRetriesOnTestFail** (optional) `Number` – set retries to the given value after the first test fail; default `Infinity` (retries will not be reset). **Option is supported only in hermione**. | ||
@@ -49,3 +50,4 @@ ### Gemini | ||
'retry-limiter/hermione': { | ||
limit: 0.3 | ||
limit: 0.3, | ||
setRetriesOnTestFail: 1 | ||
} | ||
@@ -52,0 +54,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10503
12
155
55
0