Skip to content

Instantly share code, notes, and snippets.

@lance
Last active June 19, 2017 20:38
Show Gist options
  • Save lance/da09fe89401c6240f92aa2045f10d99b to your computer and use it in GitHub Desktop.
Save lance/da09fe89401c6240f92aa2045f10d99b to your computer and use it in GitHub Desktop.
opossum rate limiting test
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
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