|
3 | 3 | * Testing dependencies
|
4 | 4 | */
|
5 | 5 | var should = require('should')
|
| 6 | + , sinon = require('sinon') |
6 | 7 | , MqttClient = require('../lib/client');
|
7 | 8 |
|
8 | 9 | module.exports = function(server, createClient, port) {
|
@@ -376,7 +377,42 @@ module.exports = function(server, createClient, port) {
|
376 | 377 | });
|
377 | 378 | });
|
378 | 379 |
|
| 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 | + |
379 | 414 | describe('pinging', function () {
|
| 415 | + |
380 | 416 | it('should set a ping timer', function (done) {
|
381 | 417 | var client = createClient(port, {keepalive: 3});
|
382 | 418 | client.once('connect', function() {
|
|
0 commit comments