Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions k6-test.js
Original file line number Diff line number Diff line change
@@ -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);
}