Skip to content

Commit

Permalink
chore: add queue reservation test
Browse files Browse the repository at this point in the history
  • Loading branch information
junha-ahn committed Nov 6, 2023
1 parent d6f0e25 commit eae086a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/performanceTest/scripts/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import exec from 'k6/execution';

const getRandomByRange = (max) => Math.floor(Math.random() * max);

export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

export const getOneFromList = (list) => list[getRandomByRange(list.length)];

export const isSuccess = (r) => r.status >= 200 && r.status < 300;
export const isFail = (r) => !isSuccess(r);


export const isAlreadReservedAll = (r) => r.status == 409 && r.json().errorCode == 50001;
export const isRunningQueueTicket = (r) => r.status == 200 && r.json().data.isWaiting == false;

export const randomInt = (start, end) => randomIntBetween(start, end);

export const getUserIDFromExec = (VU_COUNT) => exec.vu.idInTest + (VU_COUNT * exec.vu.iterationInScenario)
export const getUserIDFromExec = (VU_COUNT) => exec.vu.idInTest + (VU_COUNT * exec.vu.iterationInScenario)

17 changes: 17 additions & 0 deletions src/performanceTest/scripts/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,21 @@ export default class Request {
this.afterHook()
return res
}


createQueueTicket(eventId, userId) {
this.beforeHook()
const res = http.post(`${this.baseURL}/ticket`, JSON.stringify({eventId, userId}), this.getParams());
this.afterHook()
return res
}

getQueueTicket(eventId, userId) {
this.beforeHook()
const res = http.get(`${this.baseURL}/ticket/${eventId}/${userId}`, this.getParams());
this.afterHook()
this.afterHook()
this.afterHook()
return res
}
}
28 changes: 28 additions & 0 deletions src/performanceTest/scripts/smokeTest/queue_reservationCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { check } from "k6";
import Request from "../lib/request.js";
import generator from "../lib/generator.js";
import hooks from "../lib/hooks.js";
import { getOneFromList, isRunningQueueTicket } from "../lib/helpers.js";

export const setup = hooks.setup
export const handleSummary = hooks.handleSummary

export default function () {
const req = new Request()

const USERID = 1
const user = generator.User(USERID)
req.signup(user)
req.signin(user)
const event = getOneFromList(req.getEvents().json().data)
const res1 = req.createQueueTicket(event.id, USERID)

check(res1, { "createQueueTicket status == 201": (r) => r.status == 201 });

while (!isRunningQueueTicket(req.getQueueTicket(event.id, USERID))) {}

const res2 = req.createReservation(generator.Reservation(event.id))
console.log(res2)
check(res2, { "createReservation status == 201": (r) => r.status == 201 });
check(res2, { "createReservation.eventId == event.id": (r) => r.json().data.eventId == event.id });
}
68 changes: 68 additions & 0 deletions src/performanceTest/scripts/spikeTest/queue_spikeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { check } from "k6";
import Request from "../lib/request.js";
import { encode } from "../lib/jwt.js";
import hooks from "../lib/hooks.js";
import generator from "../lib/generator.js";
import { isSuccess, randomInt, isAlreadReservedAll, isRunningQueueTicket } from "../lib/helpers.js";

export const setup = hooks.setup
export const handleSummary = hooks.handleSummary

export const options = {
tags: {
testid: `${__ENV.ENTRYPOINT}`
},
ext: {
loadimpact: {
apm: [
{
includeTestRunId: true,
}
]
}
},
scenarios: {
contacts: {
executor: 'per-vu-iterations',
vus: 200,
iterations: 1,
maxDuration: '1m',
},
},

thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
http_req_duration: ['p(95)<300'], // 95% of requests should be below 300ms
},
};


export default function () {
const req = new Request()

const ID = randomInt(1, 1000000)
req.setToken(encode(ID))

const query = {
size: 20,
page: 0,
sort: "id,asc"
}
for (let i = 0; i < 13; i++) {
check(req.getEvents(query), {"Success Get Events": isSuccess});
query.page = query.page + randomInt(1, 10)
}

const eventId = 98 // maxAttendees = 191
check(req.getEvent(eventId), {"EVENT 98 maxAttendees = 191": (r) => r.json().data.maxAttendees === 191})

const res1 = req.createQueueTicket(eventId, ID)
check(res1, { "createQueueTicket status == 201": (r) => r.status == 201 });

while (!isRunningQueueTicket(req.getQueueTicket(eventId, ID))) {}


const res = req.createReservation(generator.Reservation(eventId))
check(res, {"Success Reservation": isSuccess});
check(res, {"Already reserved": isAlreadReservedAll});
}
2 changes: 1 addition & 1 deletion src/performanceTest/scripts/spikeTest/spikeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const options = {
scenarios: {
contacts: {
executor: 'per-vu-iterations',
vus: 500,
vus: 200,
iterations: 1,
maxDuration: '1m',
},
Expand Down

0 comments on commit eae086a

Please sign in to comment.