From 793c9c5af9acf63015be0769110fd4d9b0037a91 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 9 Nov 2023 14:59:00 +0000 Subject: [PATCH] Add example throttle js test script --- examples/throttle.js | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/throttle.js 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(); + } +}