Skip to content

Commit

Permalink
feat: add performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniciusCestarii committed Dec 16, 2024
1 parent 12b883c commit 32fa3a2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/performance-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Performance Tests

on:
push:
branches:
- main
pull_request:
branches: [main]

jobs:
test:
name: Performance Tests
runs-on: ubuntu-latest

services:
postgres:
image: bitnami/postgresql
ports:
- 5432:5432
env:
POSTGRESQL_USERNAME: postgres
POSTGRESQL_PASSWORD: postgres
POSTGRESQL_DATABASE: modular-pets

steps:
- uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38

- name: Install Dependencies
run: bun install --frozen-lockfile

- name: Install K6
run: sudo apt-get update && sudo apt-get install -y k6

- name: Run Performance Tests
run: bun run ci:test:performance
env:
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/modular-pets"
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"start": "NODE_ENV=production bun dist/app.js",
"test": "bun test src/modules/pet/pets/use-cases/ src/modules/pet/species/use-cases/ src/modules/pet/breeds/use-cases/ src/modules/health/patients/use-cases/",
"test:e2e": "bun test src/modules/pet/pets/controllers/ src/modules/pet/species/controllers/ src/modules/pet/breeds/controllers/ src/modules/health/patients/controllers/ --preload src/modules/shared/utilities/test-setup.ts",
"test:performance": "k6 run --out web-dashboard scripts/performance.test.ts",
"ci:test:performance": "k6 run scripts/performance.test.ts",
"generate": "drizzle-kit generate",
"migrate": "drizzle-kit migrate",
"lint": "eslint --fix",
Expand All @@ -30,6 +32,7 @@
"devDependencies": {
"@eslint/js": "^9.15.0",
"@types/bun": "latest",
"@types/k6": "^0.54.2",
"@types/pg": "^8.11.10",
"drizzle-kit": "^0.28.1",
"eslint": "^9.15.0",
Expand Down
26 changes: 26 additions & 0 deletions scripts/performance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import http from "k6/http";

export const options = {
stages: [
{ duration: "30s", target: 20 },
{ duration: "1m", target: 60 },
{ duration: "30s", target: 0 },
],
thresholds: {
http_req_duration: ["avg<100", "p(95)<200"],
http_reqs: ["rate>2000"],
},
noConnectionReuse: true,
};

export default function () {
const data = {
name: "Dog",
};

// basic POST request (first 201 created, then 409 conflict)

http.post("http://localhost:3333/species", JSON.stringify(data), {
headers: { "Content-Type": "application/json" },
});
}

0 comments on commit 32fa3a2

Please sign in to comment.