Skip to content

Commit

Permalink
Ensure the pending queue is purged after error
Browse files Browse the repository at this point in the history
  • Loading branch information
argon committed Sep 24, 2016
1 parent 15f00dd commit 56a13a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ module.exports = function (dependencies) {
this.endpointManager.on("error", (err) => {
this.queue.forEach((resolve) => {
resolve(Promise.reject(err));
})
});

this.queue = [];
});

this.queue = [];
Expand Down
12 changes: 9 additions & 3 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ describe("Client", function () {
});

context("connection fails", function () {
let promises;
let promises, client;

beforeEach( function() {
const client = new Client( { address: "testapi" } );
client = new Client( { address: "testapi" } );

fakes.endpointManager.getStream.onCall(0).returns(fakes.streams[0]);

Expand Down Expand Up @@ -504,7 +504,13 @@ describe("Client", function () {
expect(response[1]).to.deep.equal({ device: "adfe5969", error: new Error("endpoint failed") });
expect(response[2]).to.deep.equal({ device: "abcd1335", error: new Error("endpoint failed") });
})
})
});

it("clears the queue", function () {
return promises.then( () => {
expect(client.queue.length).to.equal(0);
});
});
});

});
Expand Down

0 comments on commit 56a13a9

Please sign in to comment.