-
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.
fix: Clear reset timer on open() (#383)
* add failing test * clear reset timeout on open() * clear warmum timeout on shutdown()
- Loading branch information
1 parent
7b92602
commit 7f488f1
Showing
2 changed files
with
47 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const CircuitBreaker = require('../'); | ||
const { timedFailingFunction } = require('./common'); | ||
|
||
test('when open() is called it cancels the resetTimeout', t => { | ||
t.plan(5); | ||
const options = { | ||
errorThresholdPercentage: 1, | ||
resetTimeout: 100 | ||
}; | ||
|
||
const breaker = new CircuitBreaker(timedFailingFunction, options); | ||
breaker.fire(0) | ||
.then(t.fail) | ||
.catch(e => t.equals(e, 'Failed after 0')) | ||
.then(() => { | ||
t.ok(breaker.opened, 'should be open after initial fire'); | ||
t.notOk(breaker.pendingClose, | ||
'should not be pending close after initial fire'); | ||
breaker.open(); | ||
}); | ||
|
||
setTimeout(() => { | ||
t.ok(breaker.opened, 'should not have been opened by the resetTimeout'); | ||
t.notOk(breaker.pendingClose, | ||
'should still not be pending close'); | ||
t.end(); | ||
}, options.resetTimeout * 1.5); | ||
}); |