Skip to content

Commit

Permalink
try adding concurrency test
Browse files Browse the repository at this point in the history
  • Loading branch information
fredzqm committed Nov 2, 2018
1 parent 2d2849d commit 0fb7eca
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ describe("Queue", () => {
});
});

it("should handle tasks in concurrency", () => {
const handler = sinon
.stub()
.rejects(TEST_ERROR)
.withArgs("1")
.onCall(2)
.resolves(0)
.withArgs("2")
.onCall(2)
.resolves(0);

const q = new Queue({
backoff: 0,
concurrency: 2,
handler,
retries: 3,
});

q.add("1");
q.add("2");
q.close();

return q
.wait()
.catch((err: Error) => {
throw new Error("handler should have passed " + q.stats());
})
.then(() => {
expect(handler.callCount).to.equal(6);
expect(q.complete).to.equal(2);
expect(q.success).to.equal(2);
expect(q.errored).to.equal(0);
expect(q.retried).to.equal(4);
});
});

it("should retry the number of retries for mutiple tasks", () => {
const handler = sinon
.stub()
Expand All @@ -140,6 +176,7 @@ describe("Queue", () => {

const q = new Queue({
backoff: 0,
concurrency: 1,
handler,
retries: 3,
});
Expand Down

0 comments on commit 0fb7eca

Please sign in to comment.