diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 05b1e5a..95b3f31 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,32 +2,49 @@ 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: 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: Initialize database - run: | - python init_db.py - - - name: Run tests with pytest - run: | - pytest -v + - name: Checkout code + uses: actions/checkout@v3 + + - 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: Initialize database + run: | + python init_db.py + + - name: Run tests with pytest + run: | + pytest -v + + - name: Install k6 + run: | + sudo gpg -k + sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69 + echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list + sudo apt-get update + sudo apt-get install k6 + + - name: Start FastAPI server + run: | + uvicorn app.main:app --host 0.0.0.0 --port 8000 & + sleep 5 # 서버가 시작될 때까지 대기 + + - name: Run k6 load test on slow endpoint + run: | + k6 run k6-test.js -e BASE_URL=http://127.0.0.1:8000 diff --git a/k6-test.js b/k6-test.js new file mode 100644 index 0000000..a0797c2 --- /dev/null +++ b/k6-test.js @@ -0,0 +1,21 @@ +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}, + ], + threholds: { + http_req_duration: ["p(95)<500"], + } +} + +export default function () { + const rest = http.get("http://localhost:8000/api/posts/v1/slow"); + check(rest, { + "is status 200": (r) => r.status === 200, + }); + sleep(1); +} \ No newline at end of file