-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add options.allowWarmUp as a creation option (#218)
This feature allows the user to let the circuit warm up before opening, even if every request is a failure or timeout. The warmup duration is the value provided for options.rollingCountTimeout. Fixes: #217
- Loading branch information
Showing
4 changed files
with
112 additions
and
4 deletions.
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
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
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
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,64 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const opossum = require('../'); | ||
const { passFail } = require('./common'); | ||
|
||
test('By default does not allow for warmup', t => { | ||
t.plan(3); | ||
const options = { | ||
errorThresholdPercentage: 1, | ||
resetTimeout: 100 | ||
}; | ||
|
||
const breaker = opossum(passFail, options); | ||
breaker.fire(-1) | ||
.catch(e => t.equals(e, 'Error: -1 is < 0')) | ||
.then(() => { | ||
t.ok(breaker.opened, 'should be open after initial fire'); | ||
t.notOk(breaker.pendingClose, | ||
'should not be pending close after initial fire'); | ||
}); | ||
}); | ||
|
||
test('Allows for warmup when option is provided', t => { | ||
t.plan(3); | ||
const options = { | ||
errorThresholdPercentage: 1, | ||
resetTimeout: 100, | ||
allowWarmUp: true | ||
}; | ||
|
||
const breaker = opossum(passFail, options); | ||
breaker.fire(-1) | ||
.catch(e => t.equals(e, 'Error: -1 is < 0')) | ||
.then(() => { | ||
t.notOk(breaker.opened, 'should not be open after initial fire'); | ||
t.notOk(breaker.pendingClose, | ||
'should not be pending close after initial fire'); | ||
}); | ||
}); | ||
|
||
test('Only warms up for rollingCountTimeout', t => { | ||
t.plan(4); | ||
const options = { | ||
errorThresholdPercentage: 1, | ||
resetTimeout: 100, | ||
allowWarmUp: true, | ||
rollingCountTimeout: 500 | ||
}; | ||
|
||
const breaker = opossum(passFail, options); | ||
breaker.fire(-1) | ||
.catch(e => t.equals(e, 'Error: -1 is < 0')) | ||
.then(() => { | ||
t.notOk(breaker.opened, 'should not be open after initial fire'); | ||
t.notOk(breaker.pendingClose, | ||
'should not be pending close after initial fire'); | ||
}) | ||
.then(() => { | ||
setTimeout(_ => { | ||
t.notOk(breaker.warmUp, 'Warmup should end after rollingCountTimeout'); | ||
}, 500); | ||
}); | ||
}); |