Skip to content

Commit 021702e

Browse files
committed
keepalive interval should be in 1000 milliseconds
1 parent 9b36aa6 commit 021702e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ MqttClient.prototype._setupPingTimer = function() {
453453
this.pingResp = true;
454454
this.pingTimer = setInterval(function () {
455455
that._checkPing();
456-
}, this.options.keepalive * 600);
456+
}, this.options.keepalive * 1000);
457457
}
458458
};
459459

test/abstract_client.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Testing dependencies
44
*/
55
var should = require('should')
6+
, sinon = require('sinon')
67
, MqttClient = require('../lib/client');
78

89
module.exports = function(server, createClient, port) {
@@ -376,7 +377,42 @@ module.exports = function(server, createClient, port) {
376377
});
377378
});
378379

380+
describe('keepalive', function () {
381+
var clock;
382+
383+
beforeEach(function() {
384+
clock = sinon.useFakeTimers();
385+
});
386+
387+
afterEach(function() {
388+
clock.restore();
389+
});
390+
391+
it('should checkPing at keepalive interval', function (done) {
392+
var interval = 3,
393+
client = createClient(port, {keepalive: interval});
394+
395+
client._checkPing = sinon.spy();
396+
397+
client.once('connect', function() {
398+
399+
clock.tick(interval * 1000);
400+
client._checkPing.callCount.should.equal(1);
401+
402+
clock.tick(interval * 1000);
403+
client._checkPing.callCount.should.equal(2);
404+
405+
clock.tick(interval * 1000);
406+
client._checkPing.callCount.should.equal(3);
407+
408+
client.end()
409+
done();
410+
});
411+
});
412+
});
413+
379414
describe('pinging', function () {
415+
380416
it('should set a ping timer', function (done) {
381417
var client = createClient(port, {keepalive: 3});
382418
client.once('connect', function() {

0 commit comments

Comments
 (0)