Fix Tunnel#stop.

This commit is contained in:
John-David Dalton
2014-05-02 07:42:41 -07:00
parent 1d149b100b
commit 7e375370fa

View File

@@ -602,13 +602,16 @@ Tunnel.prototype.start = function(callback) {
console.log('Sauce Connect tunnel opened'); console.log('Sauce Connect tunnel opened');
var completed = 0, var completed = 0,
total = tunnel.jobs.length; queue = tunnel.queue,
running = tunnel.running;
push.apply(queue, tunnel.jobs);
var total = queue.length;
tunnel.emit('start'); tunnel.emit('start');
push.apply(tunnel.queue, tunnel.jobs);
_.invoke(tunnel.queue, 'on', 'complete', function() { _.invoke(queue, 'on', 'complete', function() {
_.pull(tunnel.running, this); _.pull(running, this);
if (success) { if (success) {
success = !this.failed; success = !this.failed;
} }
@@ -653,8 +656,9 @@ Tunnel.prototype.stop = function(callback) {
} }
console.log('Shutting down Sauce Connect tunnel...'); console.log('Shutting down Sauce Connect tunnel...');
var stopped = 0, var running = this.running,
total = this.jobs.length, stopped = 0,
total = running.length,
tunnel = this; tunnel = this;
var onTunnelStop = function() { var onTunnelStop = function() {
@@ -665,12 +669,12 @@ Tunnel.prototype.stop = function(callback) {
this.stopping = true; this.stopping = true;
this.queue.length = 0; this.queue.length = 0;
if (_.isEmpty(this.running)) { if (!total) {
_.defer(onTunnelStop); _.defer(onTunnelStop);
return this; return this;
} }
_.invoke(this.running, 'stop', function() { _.invoke(running, 'stop', function() {
_.pull(tunnel.running, this); _.pull(running, this);
if (++stopped == total) { if (++stopped == total) {
tunnel.connection.stop(onTunnelStop); tunnel.connection.stop(onTunnelStop);
} }