hatoo / hatoo/oha

How to run a load test with random JSON selection?

Open
#769 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
10.5k
Forks
298
Avg merge
4h 20m
Merged PRs (30d)
5

Description

Hi! How can I run a test with random selection of JSON data for a POST request? For example, in k6 I can do it like this

```js
import {SharedArray} from 'k6/data';
import http from 'k6/http';
import { check, sleep } from 'k6';

var path = 'input.json';

const data = new SharedArray("some name", function () {
const d = JSON.parse(open(path));
console.log(d);
return d;
});

export const options = {
discardResponseBodies: false,
scenarios: {
contacts: {
executor: 'shared-iterations',
vus: 10,
iterations: 1000,
maxDuration: '100s',
},
},
};

export function setup() {

var params = {
headers: {'Content-Type': 'application/json'},
};

console.log(params);
return {headers: params};
}

export default function (setup) {

let randIndex = getRandomInt(0, data.length);
const input_params = data[randIndex];
// console.log(input_params);
const headers = setup.headers;
const res = http.post("http://127.0.0.1:8080/v2/models/bert-base-cased-squad.onnx/versions/v1/infer", JSON.stringify(input_params), headers);
check(res, {
'login succeeded': (r) => r.status === 200,
})
}

export function teardown() {
}

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}

// Run k6 run --out csv=test_results.csv script.js

```

My `input.json`

```
[
{"key":"value"},
{"key":"value"},
]
```

I would be glad to see a folder with examples for the most common cases of load testing.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.