diff --git a/lib/agent.js b/lib/agent.js index fc1b09b..f7c1dfa 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -193,7 +193,11 @@ Agent.prototype = { this._bayeux.close(); } if (this._server) { - this._server.close(cb); + try { + this._server.close(cb); + } catch (e) { + cb(); + } } }.bind(this)); } diff --git a/test/agent-test.js b/test/agent-test.js index 4c99929..7c6b631 100644 --- a/test/agent-test.js +++ b/test/agent-test.js @@ -472,5 +472,17 @@ buster.testCase("buster-ci-agent", { cb3(); assert.calledOnce(callback); } - } + }, + + "calls callback of close even if server.close throws": + function () { + + this.server.close.throws(new Error("Not running")); + this.agent = new Agent({}); + var callback = this.stub(); + + this.agent.close(callback); + + assert.calledOnce(callback); + } });