diff --git a/checkin_load_test_expand.js b/checkin_load_test_expand.js new file mode 100644 index 00000000..76f3d3a5 --- /dev/null +++ b/checkin_load_test_expand.js @@ -0,0 +1,56 @@ +// ทดสอบการยิง 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 ที่ต้องการยิง +const totalRequests = 30000; + +// ระยะเวลาทดสอบทั้งหมด +const totalDuration = 10 * 60; // 10 นาทีในหน่วยวินาที + +// จำนวน Virtual Users เฉลี่ยที่ต้องการ +const averageVus = Math.ceil(totalRequests / totalDuration); + +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 () { + // ข้อมูล payload ที่จะส่งไปยัง server + let payload = JSON.stringify({ + lat: 1, + lon: 1, + poi: 'FPT', + isLocation: true + }); + + // ตัวเลือก headers + let headers = { + 'Content-Type': 'application/json', + }; + + // ส่ง POST request + let response = http.post('https://bma-hrms.bangkok.go.th/api/v1/leave/fake-check-in', payload, { headers: headers }); + + // ตรวจสอบการตอบสนอง + check(response, { + 'is status 200': (r) => r.status === 200, + }); + + // หน่วงเวลา 1 วินาที + sleep(1); +}