Skip to content

Commit

Permalink
test: running fire in parallel
Browse files Browse the repository at this point in the history
Also new devDependency added run-parallel: 1.1.6
  • Loading branch information
helio-frota committed Jun 16, 2017
1 parent 31b6d64 commit 3d990c3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"jsdoc": "~3.4.2",
"nsp": "~2.6.2",
"opener": "~1.4.2",
"run-parallel": "^1.1.6",
"standard-version": "^4.0.0",
"szero": "^0.9.0",
"tap-spec": "~4.1.1",
Expand Down
62 changes: 62 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,68 @@ test('Semaphore capacity limit', (t) => {
});
});

test('Semaphore capacity limit in parallel', (t) => {
const parallel = require('run-parallel');
t.plan(24);
const breaker = cb('foobar', { capacity: 1 });

const tasks = [
() => {
breaker.fire()
.then((result) => {
t.ok(true, `semaphore count is: ${breaker.semaphore.count} and initial capacity is: ${breaker.options.capacity}`);
t.ok(true, `failures: ${breaker.stats.failures}`);
t.ok(true, `fallbacks: ${breaker.stats.fallbacks}`);
t.ok(true, `successes: ${breaker.stats.successes}`);
t.ok(true, `rejects: ${breaker.stats.rejects}`);
t.ok(true, `fires: ${breaker.stats.fires}`);
})
.catch(t.fail);
},
() => {
breaker.fire()
.then((result) => {
t.ok(true, `semaphore count is: ${breaker.semaphore.count} and initial capacity is: ${breaker.options.capacity}`);
t.ok(true, `failures: ${breaker.stats.failures}`);
t.ok(true, `fallbacks: ${breaker.stats.fallbacks}`);
t.ok(true, `successes: ${breaker.stats.successes}`);
t.ok(true, `rejects: ${breaker.stats.rejects}`);
t.ok(true, `fires: ${breaker.stats.fires}`);
})
.catch(t.fail);
},
() => {
breaker.fire()
.then((result) => {
t.ok(true, `semaphore count is: ${breaker.semaphore.count} and initial capacity is: ${breaker.options.capacity}`);
t.ok(true, `failures: ${breaker.stats.failures}`);
t.ok(true, `fallbacks: ${breaker.stats.fallbacks}`);
t.ok(true, `successes: ${breaker.stats.successes}`);
t.ok(true, `rejects: ${breaker.stats.rejects}`);
t.ok(true, `fires: ${breaker.stats.fires}`);
})
.catch(t.fail);
}
];

parallel(tasks, (error) => {
t.error(error);
t.fail();
});

breaker.fire()
.then((result) => {
t.ok(true, `This is not in parallel -> semaphore count is: ${breaker.semaphore.count} and initial capacity is: ${breaker.options.capacity}`);
t.ok(true, `failures: ${breaker.stats.failures}`);
t.ok(true, `fallbacks: ${breaker.stats.fallbacks}`);
t.ok(true, `successes: ${breaker.stats.successes}`);
t.ok(true, `rejects: ${breaker.stats.rejects}`);
t.ok(true, `fires: ${breaker.stats.fires}`);
})
.then(t.end)
.catch(t.fail);
});

/**
* Returns a promise that resolves if the parameter
* 'x' evaluates to >= 0. Otherwise the returned promise fails.
Expand Down

0 comments on commit 3d990c3

Please sign in to comment.