badSimulation.gatling.ts
1 import { simulation, scenario, atOnceUsers, global, getParameter, exec, pace, nothingFor, rampUsers, pause } from "@gatling.io/core"; 2 import { http } from "@gatling.io/http"; 3 4 const scenariosInfo = [ 5 { name: "Gitea HomePage", initalVU: 10, rampUpVU: 10, repeatFor: 100, delayBetween: 3, minTimeMS: 50, maxTimeMS: 321, failChancePercent: 0 }, 6 { name: "Gitea Create Issue", initalVU: 20, rampUpVU: 35, repeatFor: 60, delayBetween: 5, minTimeMS: 111, maxTimeMS: 500, failChancePercent: 1 }, 7 { name: "Gitea View Issue", initalVU: 20, rampUpVU: 35, repeatFor: 100, delayBetween: 3, minTimeMS: 70, maxTimeMS: 333, failChancePercent: 0 }, 8 { name: "Gitea Edit Issue", initalVU: 20, rampUpVU: 35, repeatFor: 60, delayBetween: 5, minTimeMS: 103, maxTimeMS: 500, failChancePercent: 1 }, 9 { name: "Gitea Delete Issue", initalVU: 20, rampUpVU: 35, repeatFor: 60, delayBetween: 5, minTimeMS: 140, maxTimeMS: 700, failChancePercent: 1 }, 10 { name: "Gitea Create Repo", initalVU: 10, rampUpVU: 20, repeatFor: 30, delayBetween: 10, minTimeMS: 500, maxTimeMS: 1200, failChancePercent: 1 }, 11 { name: "Gitea Delete Repo", initalVU: 10, rampUpVU: 20, repeatFor: 30, delayBetween: 10, minTimeMS: 500, maxTimeMS: 1500, failChancePercent: 1 }, 12 ] 13 14 const rampUpDuration = 60; 15 16 export default simulation((setUp) => { 17 const httpProtocol = http 18 .baseUrl("http://localhost:8000") 19 .acceptHeader("application/json") 20 .userAgentHeader( 21 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36" 22 ); 23 24 25 const scenarios = scenariosInfo.map((info) => { 26 return scenario(info.name).repeat(info.repeatFor).on( 27 exec( 28 http(info.name).get(`/mock-endpoint?min_time=${info.minTimeMS}&max_time=${info.maxTimeMS}&failchance=${info.failChancePercent}`), 29 pause(info.delayBetween) 30 ) 31 ); 32 }); 33 34 const assertion = global().failedRequests().count().lte(10); 35 36 setUp( 37 ...scenarios.map((scenario, i) => 38 scenario.injectOpen( 39 atOnceUsers(scenariosInfo[i].initalVU), 40 rampUsers(scenariosInfo[i].rampUpVU).during(rampUpDuration) 41 ) 42 ) 43 ) 44 .protocols(httpProtocol) 45 .assertions(assertion); 46 });