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 42c825c commit 16c8a12
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/throttle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 16c8a12

Please sign in to comment.