Skip to content

Commit 4fd6326

Browse files
authored
Merge pull request #34 from evs-broadcast/bugfix/fix_race_after_disconnect
Fix unhandled error
2 parents cc6a04e + 5f6c99e commit 4fd6326

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

device.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ DeviceTree.prototype.finishRequest = function () {
278278
self.callback = undefined;
279279
self.clearTimeout();
280280
self.activeRequest = null;
281-
self.makeRequest();
281+
try {
282+
self.makeRequest();
283+
} catch(e) {
284+
console.log("warn:" + e.message)
285+
}
282286
};
283287

284288
DeviceTree.prototype.timeoutRequest = function (id) {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "emberplus",
3-
"version": "1.7.22",
3+
"version": "1.7.23",
44
"description": "Javascript implementation of the Ember+ automation protocol",
55
"main": "index.js",
66
"scripts": {
@@ -29,6 +29,7 @@
2929
},
3030
"devDependencies": {
3131
"eslint": "^5.5.0",
32-
"jest": "^23.5.0"
32+
"jest": "^23.5.0",
33+
"sinon": "^7.4.1"
3334
}
3435
}

test/DeviceTree.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require("fs");
2+
const sinon = require("sinon");
23
const Decoder = require('../').Decoder;
34
const DeviceTree = require("../").DeviceTree;
45
const TreeServer = require("../").TreeServer;
@@ -9,6 +10,7 @@ const PORT = 9008;
910

1011
describe("DeviceTree", () => {
1112
describe("With server", () => {
13+
/** @type {TreeServer} */
1214
let server;
1315
beforeAll(() => {
1416
return Promise.resolve()
@@ -42,6 +44,26 @@ describe("DeviceTree", () => {
4244
})
4345
});
4446

47+
it("should gracefully connect and getDirectory", () => {
48+
let tree = new DeviceTree(LOCALHOST, PORT);
49+
let stub = sinon.stub(tree.client, "sendBER");
50+
stub.onFirstCall().returns();
51+
stub.onSecondCall().throws(new Error("blah"));
52+
stub.callThrough();
53+
return Promise.resolve()
54+
.then(() => tree.connect())
55+
.then(() => {tree.getDirectory().catch(() => {})})
56+
.then(() => tree.getDirectory())
57+
.then(() => {
58+
stub.restore();
59+
tree.disconnect();
60+
}, error => {
61+
stub.restore();
62+
tree.disconnect();
63+
throw error;
64+
})
65+
66+
}, 10000);
4567
it("should not disconnect after 5 seconds of inactivity", () => {
4668
return Promise.resolve()
4769
.then(() => {

0 commit comments

Comments
 (0)