Skip to content

Commit 817fbbd

Browse files
authored
feat(config): socket.io server pingTimeout config option. (#3355)
1 parent c5f3560 commit 817fbbd

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

docs/config/01-configuration-file.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ Under the hood Karma uses ts-node to transpile TypeScript to JavaScript. If the
5959
Create a JavaScript configuration file that overrides the module format.
6060
```javascript
6161
// karma.conf.js
62-
require('ts-node').register({
63-
compilerOptions: {
64-
module: 'commonjs'
65-
}
62+
require('ts-node').register({
63+
compilerOptions: {
64+
module: 'commonjs'
65+
}
6666
});
6767
require('./karma.conf.ts');
6868
```
@@ -678,6 +678,14 @@ Note: Just about all additional reporters in Karma (other than progress) require
678678

679679
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`.
680680

681+
## pingTimeout
682+
**Type** Number
683+
684+
**Default** 5000
685+
686+
**Description** Socket.io pingTimeout in ms, https://socket.io/docs/server-api/#new-Server-httpServer-options.
687+
Very slow networks may need values up to 60000. Larger values delay discovery of deadlock in tests or browser crashes.
688+
681689
## restartOnFileChange
682690
**Type:** Boolean
683691

lib/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ function normalizeConfig (config, configFilePath) {
204204
assert(helper.isNumber(config.browserSocketTimeout), 'Invalid configuration: browserSocketTimeout option must be a number.')
205205
}
206206

207+
if (config.pingTimeout) {
208+
assert(helper.isNumber(config.pingTimeout), 'Invalid configuration: pingTimeout option must be a number.')
209+
}
210+
207211
const defaultClient = config.defaultClient || {}
208212
Object.keys(defaultClient).forEach(function (key) {
209213
const option = config.client[key]
@@ -299,6 +303,7 @@ class Config {
299303
this.singleRun = false
300304
this.browsers = []
301305
this.captureTimeout = 60000
306+
this.pingTimeout = 5000
302307
this.proxies = {}
303308
this.proxyValidateSSL = true
304309
this.preprocessors = {}

lib/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function createSocketIoServer (webServer, executor, config) {
4444
destroyUpgrade: false,
4545
path: config.urlRoot + 'socket.io/',
4646
transports: config.transports,
47-
forceJSONP: config.forceJSONP
47+
forceJSONP: config.forceJSONP,
48+
// Default is 5000 in socket.io v2.x.
49+
pingTimeout: config.pingTimeout || 5000
4850
})
4951

5052
// hack to overcome circular dependency

test/unit/config.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ describe('config', () => {
383383

384384
expect(invalid).to.throw('Invalid configuration: formatError option must be a function.')
385385
})
386+
387+
it('should prevent non-numeric input for numeric options', () => {
388+
const invalid = function () {
389+
normalizeConfigWithDefaults({
390+
pingTimeout: '10000'
391+
})
392+
}
393+
expect(invalid).to.throw('Invalid configuration: pingTimeout option must be a number.')
394+
})
386395
})
387396

388397
describe('createPatternObject', () => {

0 commit comments

Comments
 (0)