Skip to content

Commit 68e470a

Browse files
committed
Better test stability.
1 parent 33611ae commit 68e470a

File tree

5 files changed

+94
-87
lines changed

5 files changed

+94
-87
lines changed

lib/client.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ function MqttClient (streamBuilder, options) {
117117

118118
// Mark connected on connect
119119
this.on('connect', function () {
120+
if (this.disconnected) {
121+
return;
122+
}
123+
120124
this.connected = true;
121125
var outStore = null;
122126
outStore = this.outgoingStore.createStream();
@@ -512,19 +516,25 @@ MqttClient.prototype.end = function (force, cb) {
512516
}
513517

514518
function closeStores () {
519+
that.disconnected = true;
515520
that.incomingStore.close(function () {
516521
that.outgoingStore.close(cb);
517522
});
518523
}
519524

520525
function finish () {
521-
that._cleanUp(force, closeStores);
526+
// defer closesStores of an I/O cycle,
527+
// just to make sure things are
528+
// ok for websockets
529+
that._cleanUp(force, setImmediate.bind(null, closeStores));
522530
}
523531

524532
if (this.disconnecting) {
525533
return true;
526534
}
527535

536+
this._clearReconnect();
537+
528538
this.disconnecting = true;
529539

530540
if (!force && 0 < Object.keys(this.outgoing).length) {
@@ -569,7 +579,7 @@ MqttClient.prototype._setupReconnect = function () {
569579
MqttClient.prototype._clearReconnect = function () {
570580
if (this.reconnectTimer) {
571581
clearInterval(this.reconnectTimer);
572-
this.reconnectTimer = false;
582+
this.reconnectTimer = null;
573583
}
574584
};
575585

@@ -596,7 +606,7 @@ MqttClient.prototype._cleanUp = function (forced, done) {
596606
);
597607
}
598608

599-
if (this.reconnectTimer) {
609+
if (!this.disconnecting) {
600610
this._clearReconnect();
601611
this._setupReconnect();
602612
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mqtt",
33
"description": "A library for the MQTT protocol",
4-
"version": "1.13.0",
4+
"version": "1.14.0",
55
"contributors": [
66
"Adam Rudd <adamvrr@gmail.com>",
77
"Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)"
@@ -19,7 +19,7 @@
1919
},
2020
"main": "mqtt.js",
2121
"scripts": {
22-
"test": "mocha",
22+
"test": "mocha --bail",
2323
"pretest": "npm run check-style",
2424
"check-style:eslint": "eslint mqtt.js lib test test/browser test/helpers",
2525
"check-style:jshint": "jshint mqtt.js lib test test/browser test/helpers",

0 commit comments

Comments
 (0)