Skip to content

Commit

Permalink
fix(runner): Make process kill timeout configurable
Browse files Browse the repository at this point in the history
Add a new user configurable property processKillTimeout to set timeout for any spawned process
Closes #2447
  • Loading branch information
vivganes committed Jan 12, 2017
1 parent 39d378d commit ffaa054
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ var normalizeConfig = function (config, configFilePath) {
throw new TypeError('Invalid configuration: formatError option must be a function.')
}

if (config.processKillTimeout && !helper.isNumber(config.processKillTimeout)) {
throw new TypeError('Invalid configuration: processKillTimeout option must be a number.')
}

var defaultClient = config.defaultClient || {}
Object.keys(defaultClient).forEach(function (key) {
var option = config.client[key]
Expand Down Expand Up @@ -321,6 +325,7 @@ var Config = function () {
this.browserDisconnectTimeout = 2000
this.browserDisconnectTolerance = 0
this.browserNoActivityTimeout = 10000
this.processKillTimeout = 2000
this.concurrency = Infinity
this.failOnEmptyTestSuite = true
this.retryLimit = 2
Expand Down
1 change: 1 addition & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ exports.isFunction = _.isFunction
exports.isString = _.isString
exports.isObject = _.isObject
exports.isArray = _.isArray
exports.isNumber = _.isNumber

var ABS_URL = /^https?:\/\//
exports.isUrlAbsolute = function (url) {
Expand Down
14 changes: 9 additions & 5 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ var baseBrowserDecoratorFactory = function (
baseLauncherDecorator,
captureTimeoutLauncherDecorator,
retryLauncherDecorator,
processLauncherDecorator
processLauncherDecorator,
processKillTimeout
) {
return function (launcher) {
baseLauncherDecorator(launcher)
captureTimeoutLauncherDecorator(launcher)
retryLauncherDecorator(launcher)
processLauncherDecorator(launcher)
processLauncherDecorator(launcher, processKillTimeout)
}
}

Expand All @@ -39,7 +40,7 @@ var Launcher = function (server, emitter, injector) {
return null
}

this.launchSingle = function (protocol, hostname, port, urlRoot, upstreamProxy) {
this.launchSingle = function (protocol, hostname, port, urlRoot, upstreamProxy, processKillTimeout) {
var self = this
return function (name) {
if (upstreamProxy) {
Expand All @@ -53,6 +54,7 @@ var Launcher = function (server, emitter, injector) {
var locals = {
id: ['value', Launcher.generateId()],
name: ['value', name],
processKillTimeout: ['value', processKillTimeout],
baseLauncherDecorator: ['factory', baseDecorator],
captureTimeoutLauncherDecorator: ['factory', captureTimeoutDecorator],
retryLauncherDecorator: ['factory', retryDecorator],
Expand Down Expand Up @@ -157,15 +159,17 @@ var Launcher = function (server, emitter, injector) {

this.launch.$inject = [
'config.browsers',
'config.concurrency'
'config.concurrency',
'config.processKillTimeout'
]

this.launchSingle.$inject = [
'config.protocol',
'config.hostname',
'config.port',
'config.urlRoot',
'config.upstreamProxy'
'config.upstreamProxy',
'config.processKillTimeout'
]

this.kill = function (id, callback) {
Expand Down
8 changes: 4 additions & 4 deletions lib/launchers/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var path = require('path')
var log = require('../logger').create('launcher')
var env = process.env

var ProcessLauncher = function (spawn, tempDir, timer) {
var ProcessLauncher = function (spawn, tempDir, timer, processKillTimeout) {
var self = this
var onExitCallback
var killTimeout = 2000
var killTimeout = processKillTimeout

this._tempDir = tempDir.getPath('/karma-' + this.id.toString())

Expand Down Expand Up @@ -134,7 +134,7 @@ var ProcessLauncher = function (spawn, tempDir, timer) {
}

ProcessLauncher.decoratorFactory = function (timer) {
return function (launcher) {
return function (launcher, processKillTimeout) {
var spawn = require('child_process').spawn

var spawnWithoutOutput = function () {
Expand All @@ -145,7 +145,7 @@ ProcessLauncher.decoratorFactory = function (timer) {
return proc
}

ProcessLauncher.call(launcher, spawnWithoutOutput, require('../temp_dir'), timer)
ProcessLauncher.call(launcher, spawnWithoutOutput, require('../temp_dir'), timer, processKillTimeout)
}
}

Expand Down

0 comments on commit ffaa054

Please sign in to comment.