Add keep alive to browser stack tests

This commit is contained in:
Chocobozzz 2024-09-18 09:19:54 +02:00
parent d5825bb55f
commit 7ead42ae6e
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 42 additions and 0 deletions

View File

@ -130,6 +130,48 @@ module.exports = {
}
},
before: function () {
require('./src/commands/upload')
// Force keep alive: https://www.browserstack.com/docs/automate/selenium/error-codes/keep-alive-not-used#Node_JS
const http = require('http')
const https = require('https')
const keepAliveTimeout = 30 * 1000
// eslint-disable-next-line no-prototype-builtins
if (http.globalAgent?.hasOwnProperty('keepAlive')) {
http.globalAgent.keepAlive = true
https.globalAgent.keepAlive = true
http.globalAgent.keepAliveMsecs = keepAliveTimeout
https.globalAgent.keepAliveMsecs = keepAliveTimeout
} else {
const agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: keepAliveTimeout
})
const secureAgent = new https.Agent({
keepAlive: true,
keepAliveMsecs: keepAliveTimeout
})
const httpRequest = http.request
const httpsRequest = https.request
http.request = function (options, callback) {
if (options.protocol === 'https:') {
options['agent'] = secureAgent
return httpsRequest(options, callback)
}
else {
options['agent'] = agent
return httpRequest(options, callback)
}
}
}
},
onPrepare: onBrowserStackPrepare,
onComplete: onBrowserStackComplete