1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00
imgproxy/k6/index.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-07-12 14:01:54 +02:00
import { randomSeed } from 'k6';
import http from 'k6/http';
import { SharedArray } from 'k6/data';
import exec from 'k6/execution';
const URL_PREFIX = "http://localhost:8082/unsafe"
export let options = {
discardResponseBodies: true,
noConnectionReuse: false,
vus: 20,
iterations: 10000,
};
randomSeed(42)
const urls = new SharedArray('urls', function () {
2022-07-13 10:52:45 +02:00
let data = JSON.parse(open('./urls.json'));
const groups = (__ENV.URL_GROUPS || "").split(",").filter((g) => g != "")
if (groups.length > 0) {
data = data.filter((d) => groups.includes(d.group))
}
2022-07-12 14:01:54 +02:00
let unshuffled = [];
data.forEach((e) => {
let url = URL_PREFIX + e.url
let weight = e.weight || 1
for (var i = 0; i < weight; i++) {
unshuffled.push(url)
}
})
let shuffled = unshuffled
.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value)
return shuffled;
});
2022-07-13 10:52:45 +02:00
if (urls.length == 0) {
throw "URLs list is empty"
}
2022-07-12 14:01:54 +02:00
export default function() {
http.get(urls[exec.scenario.iterationInTest % urls.length])
}