Last active
June 19, 2017 20:38
-
-
Save lance/da09fe89401c6240f92aa2045f10d99b to your computer and use it in GitHub Desktop.
opossum rate limiting test
This file contains hidden or 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
CircuitBreaker semaphore rate limiting | |
acquiring 1 | |
acquired 0 | |
acquiring 0 | |
✖ should be truthy | |
------------------- | |
operator: ok | |
expected: true | |
actual: false | |
at: null._onTimeout (/Users/lanceball/src/opossum/test/test.js:739:42) | |
releasing 0 | |
released 0 | |
acquired 0 | |
setting timedOut | |
✔ Breaker timed out |
This file contains hidden or 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
test('CircuitBreaker semaphore rate limiting', (t) => { | |
t.plan(2); | |
let timedOut = false; | |
const breaker = cb(timedFunction, { timeout: 1000, capacity: 1 }); | |
breaker.on('timeout', e => { | |
}); | |
// fire once to acquire the semaphore and hold it for a long time | |
breaker.fire(10000).catch(e => { | |
console.error('setting timedOut'); | |
timedOut = true; | |
t.equals(e.code, 'ETIMEDOUT', 'Breaker timed out'); | |
}); | |
setTimeout(_ => { | |
// fire again immediately | |
breaker.fire(1).then(_ => {}).then(t.ok(timedOut)).then(_ => t.end).catch(t.fail); | |
}, 10); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment