Skip to content

Commit

Permalink
[BE#348] stats의 부하테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
yeongbinim authored Dec 6, 2023
1 parent 528d4d5 commit 6f150e3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
3 changes: 1 addition & 2 deletions BE/test/load-performance/loadtest-social.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SharedArray } from 'k6/data';
import http from 'k6/http';
import { check, sleep, group } from 'k6';
import { setInterval, setTimeout, clearInterval } from 'k6/experimental/timers';
import { check, sleep } from 'k6';
import moment from 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js';
import faker from 'https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.min.js';

Expand Down
76 changes: 76 additions & 0 deletions BE/test/load-performance/loadtest-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { SharedArray } from 'k6/data';
import http from 'k6/http';
import { sleep, group } from 'k6';
import moment from 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js';

const HOST = 'http://localhost:3000';
const start_date = moment('2023-11-30');

const tokens = new SharedArray('possible tokens', function () {
const mock_users = JSON.parse(open('./loadtest-mock.json'));
return mock_users.map(({ access_token }) => access_token);
});

export const options = {
//10초만에 사용자 200명 까지 증가했다가 2분동안 유지함
scenarios: {
statsDaily: {
executor: 'ramping-vus',
startVUs: 10,
stages: [
{ duration: '10s', target: 100 },
{ duration: '2m', target: 100 },
],
exec: 'statsDaily',
},
statsWeekly: {
executor: 'ramping-vus',
startVUs: 10,
stages: [
{ duration: '10s', target: 100 },
{ duration: '2m', target: 100 },
],
exec: 'statsWeekly',
},
},
thresholds: {
http_req_duration: ['avg<200', 'p(95)<500', 'max<1000'],
},
};

function getParams() {
const token = tokens[__VU % tokens.length];
return {
headers: {
Authorization: `Bearer ${token}`,
},
};
}

export function statsDaily() {
const params = getParams();
group('일간 조회 7번', () => {
let date = start_date;
for (let i = 0; i < 7; i++) {
//오늘, 1일전, 2일전, 3일전, 4일전, 5일전, 6일전 데이터 1초마다 조회
http.get(
`${HOST}/study-logs/stats?date=${date.format('YYYY-MM-DD')}`,
params,
);
date = date.subtract(1, 'd');
sleep(1);
}
});
}

export function statsWeekly() {
const params = getParams();
group('일주일간 조회', () => {
//일주일 동안의 데이터 조회
http.get(
`${HOST}/study-logs/stats/weekly?date=${start_date.format('YYYY-MM-DD')}`,
params,
);
sleep(1);
});
}

0 comments on commit 6f150e3

Please sign in to comment.