From 76cee1287a0ba09e55bf66a13ed3bc2a36c4abaa Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 12 May 2014 09:53:05 -0700 Subject: [PATCH] Ensure jobs are reset before the tunnel is closed. --- test/saucelabs.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/test/saucelabs.js b/test/saucelabs.js index f1835e09d..79a635b49 100644 --- a/test/saucelabs.js +++ b/test/saucelabs.js @@ -547,9 +547,11 @@ Job.prototype.restart = function(callback) { console.log(label + ' ' + description + ' restart %d of %d', ++this.attempts, this.retries); this.once('restart', _.callback(callback)); - _.defer(_.bind(this.emit, this, 'restart')); - return this.remove(this.start); + return this.remove(function() { + this.emit('restart'); + this.start(); + }); }; /** @@ -684,7 +686,6 @@ function Tunnel(properties) { completed = 0; success = true; restarted.length = 0; - _.invoke(all, 'reset'); }); this.attempts = 0; @@ -706,9 +707,24 @@ Tunnel.prototype.restart = function(callback) { console.log('Tunnel ' + this.id + ': restart %d of %d', ++this.attempts, this.retries); this.once('restart', _.callback(callback)); - _.defer(_.bind(this.emit, this, 'restart')); - return this.stop(this.start); + var jobs = this.jobs, + active = jobs.active, + reset = 0, + total = active.length, + tunnel = this; + + _.invoke(active, 'reset', function() { + _.pull(active, this); + if (++reset == total) { + tunnel.stop(function() { + this.emit('restart'); + this.start(); + }); + } + }); + + return this; }; /**