add flag to throttle cpu to get failures because of slow ci locally

This commit is contained in:
Bruno Windels 2019-04-16 14:59:35 +02:00
parent ef59c59f37
commit c40f7f6a3c
2 changed files with 9 additions and 3 deletions

View file

@ -35,13 +35,18 @@ module.exports = class RiotSession {
this.log = new Logger(this.username);
}
static async create(username, puppeteerOptions, riotserver, hsUrl) {
static async create(username, puppeteerOptions, riotserver, hsUrl, throttleCpuFactor = 1) {
const browser = await puppeteer.launch(puppeteerOptions);
const page = await browser.newPage();
await page.setViewport({
width: 1280,
height: 800
});
if (throttleCpuFactor !== 1) {
const client = await page.target().createCDPSession();
console.log("throttling cpu by a factor of", throttleCpuFactor);
await client.send('Emulation.setCPUThrottlingRate', { rate: throttleCpuFactor });
}
return new RiotSession(browser, page, username, riotserver, hsUrl);
}

View file

@ -25,8 +25,9 @@ program
.option('--no-logs', "don't output logs, document html on error", false)
.option('--riot-url [url]', "riot url to test", "http://localhost:5000")
.option('--windowed', "dont run tests headless", false)
.option('--slow-mo', "run tests slower to follow whats going on", false)
.option('--slow-mo', "type at a human speed", false)
.option('--dev-tools', "open chrome devtools in browser window", false)
.option('--throttle-cpu [factor]', "factor to slow down the cpu with", parseFloat, 1.0)
.option('--no-sandbox', "same as puppeteer arg", false)
.option('--log-directory <dir>', 'a directory to dump html and network logs in when the tests fail')
.parse(process.argv);
@ -57,7 +58,7 @@ async function runTests() {
);
async function createSession(username) {
const session = await RiotSession.create(username, options, program.riotUrl, hsUrl);
const session = await RiotSession.create(username, options, program.riotUrl, hsUrl, program.throttleCpu);
sessions.push(session);
return session;
}