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
41 changes: 21 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: |
Expand All @@ -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
k6 run k6-test.js -e BASE_URL=http://127.0.0.1:8000
24 changes: 24 additions & 0 deletions k6-test-fast.js
Original file line number Diff line number Diff line change
@@ -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);
}
34 changes: 18 additions & 16 deletions k6-test.js
Original file line number Diff line number Diff line change
@@ -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);
}
Loading