Skip to content

Commit

Permalink
feat(config): socket.io server pingTimeout config option. (#3355)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjbarton authored Aug 21, 2019
1 parent c5f3560 commit 817fbbd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
16 changes: 12 additions & 4 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ Under the hood Karma uses ts-node to transpile TypeScript to JavaScript. If the
Create a JavaScript configuration file that overrides the module format.
```javascript
// karma.conf.js
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
}
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
}
});
require('./karma.conf.ts');
```
Expand Down Expand Up @@ -678,6 +678,14 @@ Note: Just about all additional reporters in Karma (other than progress) require

The CLI option should be a path to a file that exports the format function. This can be a function exported at the root of the module or an export named `formatError`.

## pingTimeout
**Type** Number

**Default** 5000

**Description** Socket.io pingTimeout in ms, https://socket.io/docs/server-api/#new-Server-httpServer-options.
Very slow networks may need values up to 60000. Larger values delay discovery of deadlock in tests or browser crashes.

## restartOnFileChange
**Type:** Boolean

Expand Down
5 changes: 5 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ function normalizeConfig (config, configFilePath) {
assert(helper.isNumber(config.browserSocketTimeout), 'Invalid configuration: browserSocketTimeout option must be a number.')
}

if (config.pingTimeout) {
assert(helper.isNumber(config.pingTimeout), 'Invalid configuration: pingTimeout option must be a number.')
}

const defaultClient = config.defaultClient || {}
Object.keys(defaultClient).forEach(function (key) {
const option = config.client[key]
Expand Down Expand Up @@ -299,6 +303,7 @@ class Config {
this.singleRun = false
this.browsers = []
this.captureTimeout = 60000
this.pingTimeout = 5000
this.proxies = {}
this.proxyValidateSSL = true
this.preprocessors = {}
Expand Down
4 changes: 3 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function createSocketIoServer (webServer, executor, config) {
destroyUpgrade: false,
path: config.urlRoot + 'socket.io/',
transports: config.transports,
forceJSONP: config.forceJSONP
forceJSONP: config.forceJSONP,
// Default is 5000 in socket.io v2.x.
pingTimeout: config.pingTimeout || 5000
})

// hack to overcome circular dependency
Expand Down
9 changes: 9 additions & 0 deletions test/unit/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@ describe('config', () => {

expect(invalid).to.throw('Invalid configuration: formatError option must be a function.')
})

it('should prevent non-numeric input for numeric options', () => {
const invalid = function () {
normalizeConfigWithDefaults({
pingTimeout: '10000'
})
}
expect(invalid).to.throw('Invalid configuration: pingTimeout option must be a number.')
})
})

describe('createPatternObject', () => {
Expand Down

0 comments on commit 817fbbd

Please sign in to comment.