diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a7a544c..062cf1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,35 +2,36 @@ name: CI on: push: - branches: [ main, master ] + branches: [main, master] pull_request: - branches: [ main, master ] + branches: [main, master] jobs: test: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Initialize database + run: | + python init_db.py - - name: Initialize database - run: | - python init_db.py + - name: Run tests with pytest + run: | + pytest -v - - name: Run tests with pytest - run: | - pytest -v load-test: runs-on: ubuntu-latest @@ -41,7 +42,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: '3.10' - name: Install Python dependencies run: | @@ -67,4 +68,4 @@ jobs: - name: Run k6 load test on slow endpoint run: | - k6 run k6-test.js -e BASE_URL=http://127.0.0.1:8000 \ No newline at end of file + k6 run k6-test.js -e BASE_URL=http://127.0.0.1:8000 diff --git a/k6-test-fast.js b/k6-test-fast.js new file mode 100644 index 0000000..d2cb454 --- /dev/null +++ b/k6-test-fast.js @@ -0,0 +1,24 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +export const options = { + stages: [ + { duration: '10s', target: 10 }, + { duration: '20s', target: 10 }, + { duration: '10s', target: 0 }, + ], + thresholds: { + http_req_duration: ['p(95)<500'], + }, +}; + +export default function () { + const res = http.get('http://127.0.0.1:8000/api/posts/v2/fast'); + + check(res, { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + sleep(1); +} diff --git a/k6-test.js b/k6-test.js index 67206c5..0cac119 100644 --- a/k6-test.js +++ b/k6-test.js @@ -1,22 +1,24 @@ -import http from "k6/http"; -import { check, sleep } from "k6"; +import http from 'k6/http'; +import { check, sleep } from 'k6'; export const options = { - stages: [ - { duration: "10s", target: 10 }, - { duration: "20s", target: 10 }, - { duration: "10s", target: 0 }, - ], - thresholds: { - http_req_duration: ["p(95)<500"], - }, + stages: [ + { duration: '10s', target: 10 }, // 10초 동안 10명의 가상 사용자로 증가 + { duration: '20s', target: 10 }, // 20초 동안 10명 유지 + { duration: '10s', target: 0 }, // 10초 동안 0명으로 감소 + ], + thresholds: { + http_req_duration: ['p(95)<500'], // 95%의 요청이 500ms 이내여야 함 + }, }; export default function () { - const res = http.get("http://127.0.0.1:8000/api/posts/v1/slow"); - check(res, { - "is status 200": (r) => r.status === 200, - "response time < 500ms": (r) => r.timings.duration < 500, - }); - sleep(1); + const res = http.get('http://127.0.0.1:8000/api/posts/v1/slow'); + + check(res, { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + sleep(1); }