Skip to content

Commit

Permalink
Update the throttle example
Browse files Browse the repository at this point in the history
This update adds the use of throttleCPU into the example test script.
  • Loading branch information
ankur22 committed Nov 14, 2023
1 parent d396169 commit 27cd1ab
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions examples/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@ export const options = {
},
exec: 'normal',
},
throttled: {
networkThrottled: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
exec: 'throttled',
exec: 'networkThrottled',
},
cpuThrottled: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
exec: 'cpuThrottled',
},
},
thresholds: {
'browser_http_req_duration{scenario:normal}': ['p(99)<500'],
'browser_http_req_duration{scenario:throttled}': ['p(99)<1500'],
'browser_http_req_duration{scenario:networkThrottled}': ['p(99)<1500'],
'iteration_duration{scenario:normal}': ['p(99)<4000'],
'iteration_duration{scenario:cpuThrottled}': ['p(99)<10000'],
},
}

Expand All @@ -38,7 +49,7 @@ export async function normal() {
}
}

export async function throttled() {
export async function networkThrottled() {
const context = browser.newContext();
const page = context.newPage();

Expand All @@ -54,3 +65,16 @@ export async function throttled() {
page.close();
}
}

export async function cpuThrottled() {
const context = browser.newContext();
const page = context.newPage();

try {
page.throttleCPU({ rate: 4 });

await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
} finally {
page.close();
}
}

0 comments on commit 27cd1ab

Please sign in to comment.