Skip to content

Commit

Permalink
fix(web-server): Restart disconnected browser in non-singleRun mode.
Browse files Browse the repository at this point in the history
Allow browserDisconnectTolerance config option to be set in non-singleRun mode.

In some cases, the browser would get stuck in an infinite loop (e.g. because of
a faulty code/test). This blocks browser’s event loop, preventing it from
reporting back to Karma. Karma then considers the browser ‘DISCONNECTED’.

Prior to this commit, the `browserDisconnectTolerance` option will only apply
in singleRun mode. In above scenario, the end-user must restart Karma to
continue running tests inside Karma-managed browsers. This commit fixes this
problem by always honoring the aforementioned option.
  • Loading branch information
dtinth committed May 18, 2016
1 parent 9a972b1 commit f6587dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
5 changes: 0 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ var normalizeConfig = function (config, configFilePath) {
config.autoWatch = false
}

if (!config.singleRun && config.browserDisconnectTolerance) {
log.debug('browserDisconnectTolerance set to 0, because of singleRun')
config.browserDisconnectTolerance = 0
}

if (helper.isString(config.reporters)) {
config.reporters = config.reporters.split(',')
}
Expand Down
42 changes: 25 additions & 17 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,26 +292,34 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS
}
}

if (config.singleRun) {
self.on('browser_complete', function (completedBrowser) {
if (completedBrowser.lastResult.disconnected &&
completedBrowser.disconnectsCount <= config.browserDisconnectTolerance) {
self.log.info('Restarting %s (%d of %d attempts)', completedBrowser.name,
completedBrowser.disconnectsCount, config.browserDisconnectTolerance)
if (!launcher.restart(completedBrowser.id)) {
singleRunDoneBrowsers[completedBrowser.id] = true
emitRunCompleteIfAllBrowsersDone()
}
} else {
singleRunDoneBrowsers[completedBrowser.id] = true
self.on('browser_complete', function (completedBrowser) {
if (completedBrowser.lastResult.disconnected &&
completedBrowser.disconnectsCount <= config.browserDisconnectTolerance) {
self.log.info('Restarting %s (%d of %d attempts)', completedBrowser.name,
completedBrowser.disconnectsCount, config.browserDisconnectTolerance)

if (!launcher.restart(completedBrowser.id)) {
self.emit('browser_restart_failure', completedBrowser)
}
} else {
self.emit('browser_complete_with_no_more_retries', completedBrowser)
}
})

if (launcher.kill(completedBrowser.id)) {
// workaround to supress "disconnect" warning
completedBrowser.state = Browser.STATE_DISCONNECTED
}
if (config.singleRun) {
self.on('browser_restart_failure', function (completedBrowser) {
singleRunDoneBrowsers[completedBrowser.id] = true
emitRunCompleteIfAllBrowsersDone()
})
self.on('browser_complete_with_no_more_retries', function (completedBrowser) {
singleRunDoneBrowsers[completedBrowser.id] = true

emitRunCompleteIfAllBrowsersDone()
if (launcher.kill(completedBrowser.id)) {
// workaround to supress "disconnect" warning
completedBrowser.state = Browser.STATE_DISCONNECTED
}

emitRunCompleteIfAllBrowsersDone()
})

self.on('browser_process_failure', function (browserLauncher) {
Expand Down

0 comments on commit f6587dc

Please sign in to comment.