From 7ead42ae6ee83f840c26d78f2a0fc89ab3cdc4df Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Sep 2024 09:19:54 +0200 Subject: [PATCH] Add keep alive to browser stack tests --- client/e2e/wdio.browserstack.conf.ts | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/client/e2e/wdio.browserstack.conf.ts b/client/e2e/wdio.browserstack.conf.ts index 559cb88c5..124462f0b 100644 --- a/client/e2e/wdio.browserstack.conf.ts +++ b/client/e2e/wdio.browserstack.conf.ts @@ -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