Hi All,
thanks in advance, can anyone help me out I’m new in K6 scripting.
I have multiple requests in the default function (let’s say 5 http req ) and I want VUS to run parallel regardless of the sequence of requests to mimic the real-world scenario ( i.e any user can hit anyone of the requests)
Hi @ializrocks
I might misunderstand what your concrete goal is. But from what I understand, it sounds like storing the list of URLs you wish to hit in parallel in an array in the init context, and picking one up randomly from the default function logic might achieve what you want?
Something along the lines of:
import http from 'k6/http'
import { sleep, check } from 'k6'
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'
const urls = [
'https://test-api.k6.io/crocodile/1',
'https://test-api.k6.io/crocodile/2',
'https://test-api.k6.io/crocodile/3',
'https://test-api.k6.io/crocodile/4',
'https://test-api.k6.io/crocodile/5',
]
export default function () {
const url = urls[randomIntBetween(0, urls.length - 1)]
// our HTTP request, note that we are saving the response to res, which can be accessed later
const res = http.get(url)
sleep(1)
const checkRes = check(res, {
'status is 200': (r) => r.status === 200,
})
}
Please let me know if that’s helpful