diff --git a/client/constants.js b/client/constants.js index 0e8745395..b003fb72a 100644 --- a/client/constants.js +++ b/client/constants.js @@ -2,5 +2,6 @@ module.exports = { VERSION: '%KARMA_VERSION%', KARMA_URL_ROOT: '%KARMA_URL_ROOT%', KARMA_PROXY_PATH: '%KARMA_PROXY_PATH%', + BROWSER_SOCKET_TIMEOUT: '%BROWSER_SOCKET_TIMEOUT%', CONTEXT_URL: 'context.html' } diff --git a/client/main.js b/client/main.js index e59095d7b..6110db32e 100644 --- a/client/main.js +++ b/client/main.js @@ -9,12 +9,13 @@ var constants = require('./constants') var KARMA_URL_ROOT = constants.KARMA_URL_ROOT var KARMA_PROXY_PATH = constants.KARMA_PROXY_PATH +var BROWSER_SOCKET_TIMEOUT = constants.BROWSER_SOCKET_TIMEOUT // Connect to the server using socket.io http://socket.io var socket = io(location.host, { reconnectionDelay: 500, reconnectionDelayMax: Infinity, - timeout: 20000, + timeout: BROWSER_SOCKET_TIMEOUT, path: KARMA_PROXY_PATH + KARMA_URL_ROOT.substr(1) + 'socket.io', 'sync disconnect on unload': true }) diff --git a/docs/config/01-configuration-file.md b/docs/config/01-configuration-file.md index 8bc689cc2..e16b70080 100644 --- a/docs/config/01-configuration-file.md +++ b/docs/config/01-configuration-file.md @@ -793,6 +793,29 @@ If set then the following fields will be defined and can be overriden: All of Karma's urls get prefixed with the `urlRoot`. This is helpful when using proxies, as sometimes you might want to proxy a url that is already taken by Karma. +## browserSocketTimeout +**Type:** Number + +**Default:** `20000` + +**Description:** Timeout for the client socket connection (in ms). + +This configuration represents the amount of time that the client will wait for the socket +to connect. + +When running a browser in different environments, it can take different amounts of time for the +client socket to connect. If Karma cannot connect within the default timeout, you may see an +error similar to the following: +``` +ChromeHeadless have not captured in 60000ms, killing. +Trying to start ChromeHeadless again (1/2). +ChromeHeadless have not captured in 60000ms, killing. +Trying to start ChromeHeadless again (2/2). +ChromeHeadless have not captured in 60000ms, killing. +ChromeHeadless failed 2 times(timeout). Giving up. +``` +If you see this error, you can try increasing the socket connection timeout. + [plugins]: plugins.html [config/files]: files.html diff --git a/lib/config.js b/lib/config.js index 1d0369cbc..91ef8c76c 100644 --- a/lib/config.js +++ b/lib/config.js @@ -229,6 +229,10 @@ function normalizeConfig (config, configFilePath) { throw new TypeError('Invalid configuration: processKillTimeout option must be a number.') } + if (config.browserSocketTimeout && !helper.isNumber(config.browserSocketTimeout)) { + throw new TypeError('Invalid configuration: browserSocketTimeout option must be a number.') + } + const defaultClient = config.defaultClient || {} Object.keys(defaultClient).forEach(function (key) { const option = config.client[key] @@ -350,6 +354,7 @@ class Config { this.retryLimit = 2 this.detached = false this.crossOriginAttribute = true + this.browserSocketTimeout = 20000 } set (newConfig) { diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 211b53424..6ef06ef63 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -78,7 +78,8 @@ function createKarmaMiddleware ( injector, basePath, urlRoot, - upstreamProxy + upstreamProxy, + browserSocketTimeout ) { var proxyPath = upstreamProxy ? upstreamProxy.path : '/' return function (request, response, next) { @@ -129,6 +130,7 @@ function createKarmaMiddleware ( return data.replace('%KARMA_URL_ROOT%', urlRoot) .replace('%KARMA_VERSION%', VERSION) .replace('%KARMA_PROXY_PATH%', proxyPath) + .replace('%BROWSER_SOCKET_TIMEOUT%', browserSocketTimeout) }) } @@ -260,7 +262,8 @@ createKarmaMiddleware.$inject = [ 'injector', 'config.basePath', 'config.urlRoot', - 'config.upstreamProxy' + 'config.upstreamProxy', + 'config.browserSocketTimeout' ] // PUBLIC API