Permalink
Browse files

[fix] Don't start heartbeat in createSocket (#580)

  • Loading branch information...
davedoesdev authored and lpinca committed May 1, 2017
1 parent 509cf02 commit 4b13b1b8905f27cbd896d7d10019c6bf14a061d9
Showing with 24 additions and 1 deletion.
  1. +2 −1 index.js
  2. +22 −0 test/transformer.base.js
View
@@ -1092,7 +1092,8 @@ Primus.prototype.reserved.events = {
* @api public
*/
Primus.createSocket = function createSocket(options) {
- options = options || {};
+ // Make sure the temporary Primus we create below doesn't start a heartbeat
+ options = Object.assign({}, options, { pingInterval: false });
var primus = new Primus(new EventEmitter(), options);
return primus.Socket;
View
@@ -898,6 +898,28 @@ module.exports = function base(transformer, transformer_name) {
done();
});
});
+
+ it('should not start heartbeat', function (done) {
+ var orig_setInterval = setInterval
+ , called = false
+ , options = {
+ transformer: transformer,
+ pathname: server.pathname,
+ pingInterval: 60000
+ };
+ setInterval = function () {
+ called = true;
+ };
+ Primus.createSocket(options);
+ Primus.createSocket();
+ setInterval = orig_setInterval;
+ expect(options.pingInterval).to.equal(60000);
+ if (called) {
+ done(new Error('createSocket should not start a heartbeat'));
+ } else {
+ done();
+ }
+ });
});
describe('Authorization', function () {

0 comments on commit 4b13b1b

Please sign in to comment.