K6 - Open Source Load Testing Tool

k6 is Open source load testing tool and SaaS for engineering teams

Image

example script load test



import http from "k6/http";
import { check, sleep } from "k6";

export const options = {
    vus: 3, // virtual user
    duration: '60s', // duration request
};

export default function () {
    const url = 'http://localhost:8080/v2/order/checkout';

    // set payload request
	
	//phoneNumber random 12 digit
    let phoneNumber = "085222"+Math.floor(100000 + Math.random() * 900000);

    const payload = JSON.stringify({
        "clientCode": "evermos",
        "orderItems": [
            {
                "category": "pulsa",
                "customerID": phoneNumber,
                "productCode": "TSEL-100",
                "type": "airtime"
            }
        ],
        "resellerID": "10110738",
        "voucher": null,
        "isNewPayment": true
    });

    // set headers request
    const params = {
        headers: {
            'Content-type': 'application/json',
            'x-userid': '10110738',
            'x-clientid': 'client_android'
        }
    };

    let res = http.post(url, payload, params);
    check(res, {
        "status 200": (r) => r.status === 200
    });
}

how to run

k6 run [FILE_NAME].js

Image

reff : https://k6.io

author image

Founder of tarkiman.com, love programming and open source stuff. Subscribe him on Youtube Channel.

Comments