From b3e4c0c2fe7acaf0784975e78531ce110de4b9db Mon Sep 17 00:00:00 2001 From: Dom1046 Date: Mon, 9 Dec 2024 21:40:21 +0900 Subject: [PATCH] =?UTF-8?q?[add]=20=EA=B7=B8=EB=9D=BC=ED=8C=8C=EB=82=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/articleTest.js | 57 +++++++++++++++++++++++++++++++++++++++ script/boardTest.js | 53 ++++++++++++++++++++++++++++++++++++ script/docker-compose.yml | 21 +++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 script/articleTest.js create mode 100644 script/boardTest.js create mode 100644 script/docker-compose.yml diff --git a/script/articleTest.js b/script/articleTest.js new file mode 100644 index 0000000..5199d51 --- /dev/null +++ b/script/articleTest.js @@ -0,0 +1,57 @@ +//지도에서 글타래 찾기 테스트 +import http from "k6/http"; +import { check, sleep } from "k6"; + +// Test configuration +export const options = { + thresholds: { + // Assert that 99% of requests finish within 3000ms. + http_req_duration: ["p(99) < 6000"], + }, + stages: [ + { duration: "1m", target: 250 }, // 0 -> 250명 증가 30초 동안 + // { duration: "10s", target: 500 }, // 10초간 500명 유지 + { duration: "1m", target: 0 }, // 1분동안 250 -> 0으로 감소 + ], +}; + +// Authentication token +const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cGUiOiJKV1QifQ.eyJyb2xlIjoiUk9MRV9BRE1JTiIsIm5pY2tuYW1lIjoiSm9obkRvZSIsImNhdGVnb3J5IjoiQUNDRVNTX1RPS0VOIiwidXNlcklkIjoiYXpzQWQ0MTIxMjMiLCJlbWFpbCI6InJrcmt3bmoxMDQ2MjAwQGdtYWlsLmNvbSIsIm1lbWJlcklkIjo3OCwiaWF0IjoxNzMzNzI1MTkzLCJleHAiOjE3MzM3MjY5OTN9.RsLpLeL28uGsu8lKPnQ53qiAYWb2miregfk8bp3E8ds"; // 여기에 실제 토큰을 입력하세요 + +// Simulated user behavior +export default function () { + // Request payload + const payload = JSON.stringify({ + southWestLat: 35.4600, + southWestLon: 127.1390, + northEastLat: 38.5170, + northEastLon: 120.8220, + }); + + // HTTP headers + const headers = { + "Content-Type": "application/json", + "Authorization": `Bearer ${TOKEN}`, + }; + + // Send POST request + const url = "http://mallangplace.ap-northeast-2.elasticbeanstalk.com/api/v1/articles/public/articlesMarkers?articleType=lost"; + const res = http.post(url, payload, { headers }); + + // Validate response + if (res.status === 200 && res.body) { + try { + const responseBody = JSON.parse(res.body); + + check(responseBody, { + "response is not empty": () => responseBody.length > 0, + }); + } catch (e) { + console.error("JSON parsing failed: ", e.message); + } + } else { + console.error(`Request failed. Status: ${res.status}, Body: ${res.body}`); + } + + sleep(1); +} diff --git a/script/boardTest.js b/script/boardTest.js new file mode 100644 index 0000000..4b68317 --- /dev/null +++ b/script/boardTest.js @@ -0,0 +1,53 @@ +//게시글 전체 글 조회 테스트 +import http from "k6/http"; +import { check, sleep } from "k6"; + +// Test configuration +export const options = { + thresholds: { + // Assert that 99% of requests finish within 3000ms. + http_req_duration: ["p(99) < 3000"], + }, + stages: [ + { duration: "1m", target: 1000 }, // 0 -> 15명 증가 30초 동안 + // { duration: "10s", target: 500 }, // 1분간 15명 유지 + { duration: "1m", target: 0 }, // 20초 동안 15 -> 0으로 감소 + ], +}; + +// Authentication token +const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cGUiOiJKV1QifQ.eyJyb2xlIjoiUk9MRV9BRE1JTiIsIm5pY2tuYW1lIjoi6rmA64-Z7ZiEIiwiY2F0ZWdvcnkiOiJBQ0NFU1NfVE9LRU4iLCJ1c2VySWQiOiJ0ZXN0MTIzNDEyMyIsImVtYWlsIjoidGVzdC5lbWFpbDIwMTI0QHByb3ZpZGVyLm5ldCIsIm1lbWJlcklkIjoxMjMsImlhdCI6MTczMzczOTYyNSwiZXhwIjoxNzMzNzQxNDI1fQ.LwgSGH-387LHQFtc51OBvPEtPGv7x_iQOmks6kpM-b8"; // 여기에 실제 토큰을 입력하세요 + +// Simulated user behavior +export default function () { + + // HTTP headers + const headers = { + "Content-Type": "application/json", + "Authorization": `Bearer ${TOKEN}`, + }; + + // Send POST request + const url = "http://mallangplace.ap-northeast-2.elasticbeanstalk.com/api/v1/board/community/?page=1"; + + // Send GET request + const res = http.get(url, { headers }); + + // Validate response + if (res.status === 200 && res.body) { + try { + const responseBody = JSON.parse(res.body); + + check(responseBody, { + "response is not empty": () => responseBody.content.length > 0, // content는 백엔드의 응답 구조 확인 필요 + "status is 200": () => res.status === 200, + }); + } catch (e) { + console.error("JSON parsing failed: ", e.message); + } + } else { + console.error(`Request failed. Status: ${res.status}, Body: ${res.body}`); + } + + sleep(1); +} diff --git a/script/docker-compose.yml b/script/docker-compose.yml new file mode 100644 index 0000000..7b2130b --- /dev/null +++ b/script/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3.7' + +services: + influxdb: + image: influxdb:1.8 + container_name: k6-influxdb-1 + ports: + - "8086:8086" + environment: + - INFLUXDB_DB=k6 + - INFLUXDB_ADMIN_USER=admin + - INFLUXDB_ADMIN_PASSWORD=admin + + grafana: + image: grafana/grafana:9.3.8 + container_name: k6-grafana-1 + ports: + - "3000:3000" + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=admin