diff --git a/examples/throttle.js b/examples/throttle.js new file mode 100644 index 000000000..6964942d9 --- /dev/null +++ b/examples/throttle.js @@ -0,0 +1,57 @@ +import { check } from 'k6'; +import { browser } from 'k6/x/browser'; + +export const options = { + scenarios: { + normal: { + executor: 'shared-iterations', + options: { + browser: { + type: 'chromium', + }, + }, + exec: 'normal', + }, + throttled: { + executor: 'shared-iterations', + options: { + browser: { + type: 'chromium', + }, + }, + exec: 'throttled', + }, + }, + thresholds: { + 'browser_http_req_duration{scenario:normal}': ['p(99)<500'], + 'browser_http_req_duration{scenario:throttled}': ['p(99)<1500'], + }, +} + +export async function normal() { + const context = browser.newContext(); + const page = context.newPage(); + + try { + await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); + } finally { + page.close(); + } +} + +export async function throttled() { + const context = browser.newContext(); + const page = context.newPage(); + + try { + page.throttleNetwork({ + latency: 750, + downloadThroughput: 250, + uploadThroughput: 250, + }) + + await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); + } finally { + page.close(); + } +}