All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m19s
47 lines
1.9 KiB
JavaScript
47 lines
1.9 KiB
JavaScript
// ทดสอบการยิง 30,000 requests ในเวลา 10 นาที โดยให้กระจายการยิงในเวลาที่ต่างๆ กัน
|
|
|
|
import { check, sleep } from "k6";
|
|
import http from "k6/http";
|
|
import { Rate } from "k6/metrics";
|
|
|
|
export let errorRate = new Rate("errors");
|
|
|
|
// จำนวน request ที่ต้องการยิง
|
|
|
|
// ระยะเวลาทดสอบทั้งหมด
|
|
|
|
// จำนวน Virtual Users เฉลี่ยที่ต้องการ 300 users
|
|
//const averageVus = Math.ceil(totalRequests / totalDuration);
|
|
const averageVus = 300;
|
|
|
|
export let options = {
|
|
stages: [
|
|
{ duration: "2m", target: averageVus * 0.5 }, // 20% ของการทดสอบ เพิ่ม VUs เป็น 50% ของค่าเฉลี่ย
|
|
{ duration: "4m", target: averageVus }, // 40% ของการทดสอบ เพิ่ม VUs เป็น 100% ของค่าเฉลี่ย
|
|
{ duration: "2m", target: averageVus * 1.5 }, // 20% ของการทดสอบ เพิ่ม VUs เป็น 150% ของค่าเฉลี่ย
|
|
{ duration: "2m", target: 0 }, // ลด VUs ลงมาเป็น 0
|
|
],
|
|
thresholds: {
|
|
errors: ["rate<0.01"], // อัตรา error ต้องน้อยกว่า 1%
|
|
http_req_duration: ["p(95)<2000"], // 95% ของ requests ควรใช้เวลาไม่เกิน 2 วินาที
|
|
},
|
|
};
|
|
|
|
export default function () {
|
|
// ตัวเลือก headers
|
|
let headers = {
|
|
"Content-Type": "application/json",
|
|
Authorization: "Bearer {Token}",
|
|
};
|
|
|
|
// ส่ง GET request
|
|
let response = http.get("https://{URL}", { headers: headers });
|
|
|
|
// ตรวจสอบการตอบสนอง
|
|
check(response, {
|
|
"is status 200": (r) => r.status === 200,
|
|
});
|
|
|
|
// หน่วงเวลา 1 วินาที
|
|
sleep(1);
|
|
}
|