Created
October 30, 2023 16:03
-
-
Save dgzlopes/e87d65a4b6497d8ad346e9e721ed6569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sleep } from "k6"; | |
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; | |
import http from "k6/http"; | |
import { setTimeout, clearTimeout } from "k6/experimental/timers"; | |
export const options = { | |
stages: [ | |
{ duration: '5s', target: 5 }, | |
{ duration: '10s', target: 5 }, | |
{ duration: '5s', target: 0 }, | |
], | |
}; | |
export async function write() { | |
const url = `https://httpbin.test.k6.io/delay/${randomIntBetween(1, 15)}`; | |
const req = http.asyncRequest('GET', url); | |
// This runs if the request takes 10 or more seconds to complete | |
const timeout = setTimeout(function () { | |
console.log(`poll request (${__VU}/${__ITER}): ${url}`); | |
}, 10000); | |
await Promise.race([req]) | |
clearTimeout(timeout); | |
sleep(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment