Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): exit process when browser is not captured in captureTimeout... #1150

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions lib/launchers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
11 changes: 7 additions & 4 deletions lib/launchers/capture_timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
});

Expand All @@ -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);
};
};

Expand Down
7 changes: 7 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down