From 57a2172c64ec3e0cfebc7e5ceb2547e2847f7b14 Mon Sep 17 00:00:00 2001 From: binyroo Date: Mon, 4 Aug 2014 21:17:20 +0900 Subject: [PATCH] fix(server): exit process when browser is not captured in captureTimeout and singleRun is true --- lib/launcher.js | 7 +++++++ lib/launchers/base.js | 4 ++++ lib/launchers/capture_timeout.js | 11 +++++++---- lib/server.js | 7 +++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/launcher.js b/lib/launcher.js index 5ac5ee170..cfb4aa6ad 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -151,6 +151,13 @@ var Launcher = function(emitter, injector) { }; + this.areAllFinished = function() { + return !browsers.some(function(browser) { + return !browser.isFinished(); + }); + }; + + this.markCaptured = function(id) { browsers.forEach(function(browser) { if (browser.id === id) { diff --git a/lib/launchers/base.js b/lib/launchers/base.js index cdf5d88dd..4b5a1a739 100644 --- a/lib/launchers/base.js +++ b/lib/launchers/base.js @@ -95,6 +95,10 @@ var BaseLauncher = function(id, emitter) { return this.state === CAPTURED; }; + this.isFinished = function() { + return this.state === FINISHED; + }; + this.toString = function() { return this.name; }; diff --git a/lib/launchers/capture_timeout.js b/lib/launchers/capture_timeout.js index 197259483..f214b5f76 100644 --- a/lib/launchers/capture_timeout.js +++ b/lib/launchers/capture_timeout.js @@ -3,7 +3,7 @@ var log = require('../logger').create('launcher'); /** * Kill browser if it does not capture in given `captureTimeout`. */ -var CaptureTimeoutLauncher = function(timer, captureTimeout) { +var CaptureTimeoutLauncher = function(timer, captureTimeout, emitter) { if (!captureTimeout) { return; } @@ -20,7 +20,9 @@ var CaptureTimeoutLauncher = function(timer, captureTimeout) { log.warn('%s have not captured in %d ms, killing.', self.name, captureTimeout); self.error = 'timeout'; - self.kill(); + self.kill().then(function() { + emitter.emit('timeout'); + }); }, captureTimeout); }); @@ -34,9 +36,10 @@ var CaptureTimeoutLauncher = function(timer, captureTimeout) { CaptureTimeoutLauncher.decoratorFactory = function(timer, - /* config.captureTimeout */ captureTimeout) { + /* config.captureTimeout */ captureTimeout, + emitter) { return function(launcher) { - CaptureTimeoutLauncher.call(launcher, timer, captureTimeout); + CaptureTimeoutLauncher.call(launcher, timer, captureTimeout, emitter); }; }; diff --git a/lib/server.js b/lib/server.js index c623b1e9c..67c25df58 100644 --- a/lib/server.js +++ b/lib/server.js @@ -179,6 +179,13 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file disconnectBrowsers(results.exitCode); }); + globalEmitter.on('timeout', function() { + if (launcher.areAllFinished()) { + log.debug('Don\'t capture in captureTimeout, exitting.'); + disconnectBrowsers(1); + } + }); + globalEmitter.emit('run_start', singleRunBrowsers); }