Commit f80984c6 authored by hasan  khaddour's avatar hasan khaddour

Add K6 Tests

parent 1b85ee98
import http from 'k6/http';
import { check } from 'k6';
import { sleep } from 'k6';
// Define test configuration
export let options = {
vus: 100, // Number of virtual users (parallel requests)
duration: '30s', // Duration to run the test
};
export default function () {
// Define The target Java server URL
const url = 'http://localhost:8000/';
// Get a random task and input
const task = { taskName: 'TaskPrimeNumbers', input: '100000' };
const payload = `${task.taskName}&${task.input}`;
// Define request headers
const params = {
headers: {
'Content-Type': 'application/plain-text',
},
};
// Send POST request with random task and input
let res = http.post(url, payload, params);
// Check if the request succeeded (HTTP status 200)
check(res, {
'status was 200': (r) => r.status === 200,
});
// wait for 1 second between requests
sleep(0.4);
}
import http from 'k6/http';
import { check } from 'k6';
import { sleep } from 'k6';
// Define test configuration
export let options = {
vus: 100, // Number of virtual users (parallel requests)
duration: '60s', // Duration to run the test
};
// Array of task names and inputs
const tasks = [
{ taskName: 'TaskBubbleSort', input: '4,1,3,2,5' },
{ taskName: 'TaskSum', input: '9,3,7,1,6' },
{ taskName: 'TaskFactorial', input: '5' },
{ taskName: 'TaskPrimeNumbers', input: '28799' },
{ taskName: 'TaskFibonacci', input: '10' },
{ taskName: 'TaskGeometricMean', input: '2,3,4,5' },
];
function getRandomTask() {
let randomIndex = Math.floor(Math.random() * tasks.length);
return tasks[randomIndex];
}
export default function () {
// Define The target Java server URL
const url = 'http://localhost:8000/';
// Get a random task and input
const task = getRandomTask();
const payload = `${task.taskName}&${task.input}`;
// Define request headers
const params = {
headers: {
'Content-Type': 'application/plain-text',
},
};
// Send POST request with random task and input
let res = http.post(url, payload, params);
// Check if the request succeeded (HTTP status 200)
check(res, {
'status was 200': (r) => r.status === 200,
});
// wait for 0.4 second between requests
sleep(0.4);
}
import http from 'k6/http';
import { check } from 'k6';
export const options = {
vus: 1, // 1 virtual user
duration: '10s', // test for 10 seconds
};
export default function () {
// Define The target Java server URL
const url = 'http://localhost:8000';
// Define the payload
const payload = 'TaskBubbleSort&1,5,3,4,2';
// Send the POST request
const res = http.post(url, payload);
// Log the response
//console.log('Response body: ' + res.body);
// Check the status and result
check(res, {
'status is 200': (r) => r.status === 200,
'result is correct': (r) => r.body.includes('[1,2,3,4,5]'), // Expected output of sorting task
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment