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

feat(config): Add config option for browser socket timeout #3102

Merged
merged 2 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
3 changes: 2 additions & 1 deletion client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: 2000,
timeout: BROWSER_SOCKET_TIMEOUT,
path: KARMA_PROXY_PATH + KARMA_URL_ROOT.substr(1) + 'socket.io',
'sync disconnect on unload': true
})
Expand Down
23 changes: 23 additions & 0 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -350,6 +354,7 @@ class Config {
this.retryLimit = 2
this.detached = false
this.crossOriginAttribute = true
this.browserSocketTimeout = 20000
}

set (newConfig) {
Expand Down
7 changes: 5 additions & 2 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function createKarmaMiddleware (
injector,
basePath,
urlRoot,
upstreamProxy
upstreamProxy,
browserSocketTimeout
) {
var proxyPath = upstreamProxy ? upstreamProxy.path : '/'
return function (request, response, next) {
Expand Down Expand Up @@ -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)
})
}

Expand Down Expand Up @@ -268,7 +270,8 @@ createKarmaMiddleware.$inject = [
'injector',
'config.basePath',
'config.urlRoot',
'config.upstreamProxy'
'config.upstreamProxy',
'config.browserSocketTimeout'
]

// PUBLIC API
Expand Down