Skip to content

Commit

Permalink
Load Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorias committed Sep 10, 2024
1 parent c40a98a commit ef6ae94
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/dast-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: deploy

on:
push:
branches: ["main"]
#Se cambia nombre del branch para evitar que se ejecute para ejecutar otros labs nombre original: main
branches: ["main-test"]

jobs:
build:
Expand Down
34 changes: 31 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: deploy
on:
push:
#Se cambia nombre del branch para evitar que se ejecute para ejecutar otros labs nombre original: main
branches: [ "main-temp" ]
branches: [ "main" ]
env:
REGISTRY: antarescr
IMAGE_NAME: rest_api
Expand Down Expand Up @@ -102,4 +101,33 @@ jobs:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest


#LoadTest
LoadTest:
name: Load Testing
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
name: Checkout code

- name: Set up
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Dependencies
run: |
npm install -g artillery
npm install --save-dev artillery-plugin-ensure
- name: Run container
run: |
docker run -d --name rest-api -p 3000:3000 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Run Load Test
run: |
set -e # Detiene el workflow si la prueba de carga falla.
artillery run loadTest/basic.yaml || exit 1
36 changes: 36 additions & 0 deletions loadTest/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
config:
target: "http://localhost:3000"
plugins:
expect: {}
ensure:
p95: 200 # 95% < 200ms; para ser satisfactorio.
maxErrorRate: 2 # 2% de error permitido (timeouts, server error, bad request, etc.)

phases:
- duration: 5
arrivalRate: 1 # 1 request/s
name: "Warming up"

- duration: 10
arrivalRate: 2 # 2 request/s
rampTo: 100 # hasta 100 request/s en 7segundos
name: "Ramping up"

- duration: 15
arrivalRate: 10 # 10 request/s
name: "Sustained load"

scenarios:
- name: "Healthcheck"
flow:
- get:
url: "/healthcheck"
expect:
- statusCode: 200

- name: "Delay"
flow:
- get:
url: "/delay?seconds=0.1"
expect:
- statusCode: 200
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"winston": "^3.8.2"
},
"devDependencies": {
"artillery-plugin-ensure": "^1.14.0",
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^4.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ router.get('/search', (req, res) => {
const query = req.query.q;

// Vulnerable rendering
res.send(`<h1>Search Results for: ${query}</h1>`);
//res.send(`<h1>Search Results for: ${query}</h1>`);
//Se corrige vulnerabilidad
//res.send({ query: query });
res.send({ query: query });

});

Expand Down

0 comments on commit ef6ae94

Please sign in to comment.