Skip to content

Commit

Permalink
Add example throttle js test script
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Nov 9, 2023
1 parent c4cfdfc commit 793c9c5
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/throttle.js
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 793c9c5

Please sign in to comment.