diff --git a/lib/cradle.js b/lib/cradle.js index e85c383..c00b4c1 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -170,10 +170,18 @@ cradle.Connection.prototype.rawRequest = function (options, callback) { // Close all underlying sockets associated with the agent for the connection. // cradle.Connection.prototype.close = function () { - this.agent.sockets.forEach(function (socket) { - socket.end(); - }); -} + var agentSockets = this.agent.sockets, + sockets = agentSockets.forEach ? agentSockets : + Object.keys(agentSockets).map(function (addr) { + return agentSockets[addr]; + }).reduce(function (x, y) { + return x.concat(y); + }, []); + + sockets.forEach(function (socket) { + socket.end(); + }); +}; // // Connection.request() diff --git a/test/connection-test.js b/test/connection-test.js index b12c543..5c0ebbc 100644 --- a/test/connection-test.js +++ b/test/connection-test.js @@ -25,6 +25,9 @@ vows.describe('cradle/connection').addBatch({ assert.equal(c.options.milk, 'white'); assert.equal(c.options.cache, true); }, + "should be able to close the Connection": function (c) { + c.close(); + }, "with just a {} passed to a new Connection object": { topic: function () { return new(cradle.Connection)({milk: 'green'}) }, "should override the defaults": function (c) {