Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages are out of order due to behaviour of priorityQueue #346

Merged
merged 4 commits into from May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/clients/client.js
Expand Up @@ -59,7 +59,7 @@ function BaseAPIClient(token, opts) {
* @type {Object}
* @private
*/
this.requestQueue = async.priorityQueue(
this.requestQueue = async.queue(
bind(this._callTransport, this),
clientOpts.maxRequestConcurrency || 3
);
Expand Down
31 changes: 31 additions & 0 deletions test/clients/web/client.js
Expand Up @@ -72,6 +72,37 @@ describe('Web API Client', function () {
});
});

it('should make API calls in the order they are executed', function (done) {
var args1 = {
headers: {},
statusCode: 200,
body: '{"test": 10}'
};

var args2 = {
headers: {},
statusCode: 200,
body: '{"test": 20}'
};

var client = new WebAPIClient('test-token', { transport: mockTransport });
sinon.spy(client, 'transport');

client._makeAPICall('test', args1, null, function () {
expect(client.transport.callCount).to.equal(1);
expect(client.transport.args[0][0].data.body).to.equal('{"test": 10}');
expect(client.transport.args.length).to.equal(1);
});
client._makeAPICall('test', args2, null, function () {
expect(client.transport.callCount).to.equal(2);
expect(client.transport.args[0][0].data.body).to.equal('{"test": 10}');
expect(client.transport.args[1][0].data.body).to.equal('{"test": 20}');
expect(client.transport.args.length).to.equal(2);

});
done();
});

it('should not crash when no callback is supplied to an API request', function () {
var client = new WebAPIClient('test-token', { transport: mockTransport });

Expand Down