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

[test] Avoid Rate Limit Exceeded #1059

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const browserStack = {

process.env.CHROME_BIN = require('puppeteer').executablePath();

// BrowserStack rate limit after 1600 calls every 5 minutes.
// Per second, https://www.browserstack.com/docs/automate/api-reference/selenium/introduction#rest-api-projects
const MAX_REQUEST_PER_SECOND_BROWSERSTACK = 1600 / (60 * 5);
// Estimate the max number of concurrent karma builds
// For each PR, 4 concurrent builds are used, only one is using BrowserStack.
const AVERAGE_KARMA_BUILD = 1 / 4;
// CircleCI accepts up to 83 concurrent builds.
const MAX_CIRCLE_CI_CONCURRENCY = 83;

// Karma configuration
module.exports = function setKarmaConfig(config) {
const baseConfig = {
Expand Down Expand Up @@ -153,6 +162,15 @@ module.exports = function setKarmaConfig(config) {
},
},
};

// -1 because chrome headless runs in the local machine
const browserstackBrowsersUsed = newConfig.browsers.length - 1;

// default 1000, Avoid Rate Limit Exceeded
newConfig.pollingTimeout =
((MAX_CIRCLE_CI_CONCURRENCY * AVERAGE_KARMA_BUILD * browserstackBrowsersUsed) /
MAX_REQUEST_PER_SECOND_BROWSERSTACK) *
1000;
}

config.set(newConfig);
Expand Down