prevent callback(err) from messing with shutdown
This commit is contained in:
parent
2e0b92f1bc
commit
67f0386bb5
|
@ -346,8 +346,13 @@ Robot.prototype.halt = function(callback) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
var devices = _.pluck(this.devices, "halt"),
|
// ensures callback(err) won't prevent others from halting
|
||||||
connections = _.pluck(this.connections, "disconnect");
|
function wrap(fn) {
|
||||||
|
return function(cb) { fn.call(null, cb.bind(null, null)); };
|
||||||
|
}
|
||||||
|
|
||||||
|
var devices = _.pluck(this.devices, "halt").map(wrap),
|
||||||
|
connections = _.pluck(this.connections, "disconnect").map(wrap);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_.parallel(devices, function() {
|
_.parallel(devices, function() {
|
||||||
|
|
|
@ -463,13 +463,8 @@ describe("Robot", function() {
|
||||||
device = bot.devices.ping;
|
device = bot.devices.ping;
|
||||||
connection = bot.connections.loopback;
|
connection = bot.connections.loopback;
|
||||||
|
|
||||||
stub(device, "halt").yields(true);
|
stub(device, "halt").yields();
|
||||||
stub(connection, "disconnect").yields(true);
|
stub(connection, "disconnect").yields();
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
device.halt.restore();
|
|
||||||
connection.disconnect.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls #halt on all devices and connections", function() {
|
it("calls #halt on all devices and connections", function() {
|
||||||
|
@ -478,6 +473,38 @@ describe("Robot", function() {
|
||||||
expect(device.halt).to.be.called;
|
expect(device.halt).to.be.called;
|
||||||
expect(connection.disconnect).to.be.called;
|
expect(connection.disconnect).to.be.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
context("if a subcall triggers it's callback with an error", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
bot = new Robot({
|
||||||
|
devices: {
|
||||||
|
ping: { driver: "ping" },
|
||||||
|
ping2: { driver: "ping" }
|
||||||
|
},
|
||||||
|
|
||||||
|
connections: {
|
||||||
|
loopback: { adaptor: "loopback" },
|
||||||
|
loopback2: { adaptor: "loopback" }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.running = true;
|
||||||
|
|
||||||
|
stub(bot.devices.ping, "halt").yields("error!");
|
||||||
|
stub(bot.devices.ping2, "halt").yields();
|
||||||
|
stub(bot.connections.loopback, "disconnect").yields("another err!");
|
||||||
|
stub(bot.connections.loopback2, "disconnect").yields();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("doesn't effect the rest of the shutdown", function() {
|
||||||
|
bot.halt();
|
||||||
|
|
||||||
|
expect(bot.devices.ping.halt).to.be.called;
|
||||||
|
expect(bot.devices.ping2.halt).to.be.called;
|
||||||
|
expect(bot.connections.loopback.disconnect).to.be.called;
|
||||||
|
expect(bot.connections.loopback2.disconnect).to.be.called;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#toString", function() {
|
describe("#toString", function() {
|
||||||
|
|
Loading…
Reference in New Issue